2016-08-09 10 views
1

私は、PHPのpreg_match_allでURLからニュースIDを取得したいと思います。preg_match_all単語のある単語の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のみ

答えて

0

簡単な方法を取得する必要があります。

のような何か:

//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] = > -0 [1] => 0) –

+0

アップデート、正常、動作 –

+0

私のsql selectと同じようにするには? –