Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php preg_match()正则表达式模式从我的url中检索3个内容_Php_Regex_Preg Match - Fatal编程技术网

Php preg_match()正则表达式模式从我的url中检索3个内容

Php preg_match()正则表达式模式从我的url中检索3个内容,php,regex,preg-match,Php,Regex,Preg Match,我是PHP正则表达式模式的新手,所以我尝试为这个URL创建一个模式: $turl=http://ss-3.domian.com/screenshot/50/18/screenshot_multiple/501800/501800_multiple_1_extra_large.jpg 我只想找回3件东西:“3”,“50/18”,“501800” 所以我用了这个代码: preg_match('#http://ss-(.*?).domain.com/screenshot/(.*?)/screens

我是PHP正则表达式模式的新手,所以我尝试为这个URL创建一个模式:

$turl=http://ss-3.domian.com/screenshot/50/18/screenshot_multiple/501800/501800_multiple_1_extra_large.jpg 
我只想找回3件东西:“3”,“50/18”,“501800”

所以我用了这个代码:

preg_match('#http://ss-(.*?).domain.com/screenshot/(.*?)/screenshot_multiple/(.*?)/(.*?)_multiple_1_extra_large\.jpg#',$turl,$t_url)
所以如果我使用
$matches[1]=3$匹配[2]=50/18$匹配[3]=501800
,我应该得到正确的数字???


<?php
$turl = 'http://ss-3.domain.com/screenshot/50/18/screenshot_multiple/501800/501800_multiple_1_extra_large.jpg';
preg_match_all('#http://ss\-([^\.]*)\.domain.com/[^/]+/([^/]*)/([^/]*)/[^/]*/([^/]*)/([^/]*)#msi',$turl,$match);
// For testing
var_dump($match);
?>

您在搜索字符串中有一个输入错误(domian),但它不在引号中。这种URL很可能会改变,所以我在保持形状的同时尽可能使其通用。我想如果我们知道你的问题,如果可能的话,我们会重新考虑使用正则表达式。另外,阅读中的函数声明是一个很大的帮助,可以让您更好地理解它们的应用程序。

您是否考虑过尝试,看看它是否满足您的需要?是的,我尝试过,但它给出了一个错误:(那么您的问题为什么会问它是否“shud”工作?你是在问PHP中是否有错误吗?声明它不工作并发布收到的错误消息似乎更有效率。没有给出错误意味着没有问题得到解决。如果你使用正则表达式,那么试试regex coach。它会给你更多关于regex的反馈,以及为什么它不匹配某些字符串。