Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.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_用单词匹配url的所有id_Php_Preg Match All - Fatal编程技术网

Php preg_用单词匹配url的所有id

Php preg_用单词匹配url的所有id,php,preg-match-all,Php,Preg Match All,我想用php preg_match_all从URL获取新闻id $pattern = '%^(http://xxxxx/t)([0-9].?)+^(-)+(:[0-9]+)?(/.*)?$%i'; $m = preg_match_all($pattern,$uu,$matches); print_r ($matches); URL格式示例: http://www.xxxx.com/t1134133-0 http://www.xxxx.com/t113413

我想用php preg_match_all从URL获取新闻id

     $pattern = '%^(http://xxxxx/t)([0-9].?)+^(-)+(:[0-9]+)?(/.*)?$%i';

         $m = preg_match_all($pattern,$uu,$matches);    
print_r ($matches);
URL格式示例:

http://www.xxxx.com/t1134133-0
http://www.xxxx.com/t1134133-news-news-worlds
http://www.xxxx.com/t1134133-mi%20&ffjfj

我只需要得到1134133

简单的方法是先得到最后一部分,然后用正则表达式得到数字部分

比如:

//get the last part
$arrayUrl=explode("/",$url);
$finalPath=$arrayUrl[count($arrayUrl)-1];

preg_match("/\d+/",$finalPath,$matches);
或者,如果您非常确定url模式与OP中的示例完全相似,您甚至可以像这样做

preg_match("/\d+/",$url,$matches); // where url is `http://www.xxxx.com/t1134133-mi%20&ffjfj`

简单的方法是先获取最后一部分,然后使用正则表达式获取数字部分

比如:

//get the last part
$arrayUrl=explode("/",$url);
$finalPath=$arrayUrl[count($arrayUrl)-1];

preg_match("/\d+/",$finalPath,$matches);
或者,如果您非常确定url模式与OP中的示例完全相似,您甚至可以像这样做

preg_match("/\d+/",$url,$matches); // where url is `http://www.xxxx.com/t1134133-mi%20&ffjfj`

数组([0]=>-0[1]=>0)如何处理我的sql选择?您将使用
where news\u ID像“%whater%”
Array([0]=>-0[1]=>0)如何处理我的sql选择?您将使用
where news\u ID像“%whater%”