gpt4 book ai didi

php - 此模式的 preg_match_all

转载 作者:搜寻专家 更新时间:2023-10-31 21:09:49 25 4
gpt4 key购买 nike

我有这个模式,我想用它来提取/image/字段后的数字,我已经尝试过这个模式,我已经在 http://www.functions-online.com/preg_match_all.html 上在线查看了。它为第一个链接提供了所需的输出,但对于其他链接,它没有提供所需的输出这是我的模式

  /\sample.com\/image\/(.*)\//

这是我的字符串

     Mario Ermito photos by sample.com Mario Ermito Latest News, Photos, Biography, Videos and Wallpapers [img]http://xyz.sample.com/image/4205476/600full-mario-ermito.jpg[/img][img]http://xyz.sample.com/image/4453948/600full-my-profile.jpg[/img][img]http://xyz.sample.com/image/427185/600full-eagle-eye-poster.jpg[/img][img]http://xyz.sample.com/image/1323868/600full-alexis-bledel.jpg[/img][img]http://xyz.sample.com/image/2505314/600full-monroe-lee.jpg[/img][img]http://xyz.sample.com/image/3300481/600full-cindy-crawford.jpg[/img][img]http://xyz.sample.com/image/1046646/600full-pitura-freska.jpg[/img][img]http://xyz.sample.com/image/4322305/600full-kristin-kreuk.jpg[/img][img]http://xyz.sample.com/image/4261476/600full-kang-so--ra.jpg[/img][img]http://xyz.sample.com/image/3386911/600full-summer-brielle.jpg[/img][img]http://xyz.sample.com/image/4663949/600full-the-closer-artwork.jpg[/img]

例如

我只想在/image/字段后提取数字我不想要图像名称我想要的输出是

     4205476
4453948
427185

等字符串中的所有数字

最佳答案

使用这个正则表达式~\/\image\/(.*?)\/~

<?php
$str=' Mario Ermito photos by sample.com Mario Ermito Latest News, Photos, Biography, Videos and Wallpapers [img]http://xyz.sample.com/image/4205476/600full-mario-ermito.jpg[/img][img]http://xyz.sample.com/image/4453948/600full-my-profile.jpg[/img][img]http://xyz.sample.com/image/427185/600full-eagle-eye-poster.jpg[/img][img]http://xyz.sample.com/image/1323868/600full-alexis-bledel.jpg[/img][img]http://xyz.sample.com/image/2505314/600full-monroe-lee.jpg[/img][img]http://xyz.sample.com/image/3300481/600full-cindy-crawford.jpg[/img][img]http://xyz.sample.com/image/1046646/600full-pitura-freska.jpg[/img][img]http://xyz.sample.com/image/4322305/600full-kristin-kreuk.jpg[/img][img]http://xyz.sample.com/image/4261476/600full-kang-so--ra.jpg[/img][img]http://xyz.sample.com/image/3386911/600full-summer-brielle.jpg[/img][img]http://xyz.sample.com/image/4663949/600full-the-closer-artwork.jpg[/img]';
preg_match_all('~\/\image\/(.*?)\/~', $str, $matches);
print_r($matches[1]);

输出:

Array
(
[0] => 4205476
[1] => 4453948
[2] => 427185
[3] => 1323868
[4] => 2505314
[5] => 3300481
[6] => 1046646
[7] => 4322305
[8] => 4261476
[9] => 3386911
[10] => 4663949
)

enter image description here

关于php - 此模式的 preg_match_all,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22952769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com