mikel atef mikel atef - 1 year ago 152
PHP Question

preg_match_all id of url with words

I want to get the news id from URL with php preg_match_all;

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

$m = preg_match_all($pattern,$uu,$matches);
print_r ($matches);

Example URL formats:


i need to get 1134133 only

Answer Source

Simple way would be get the last part first and then do regex to get numeric part.

Something like:

//get the last part


or If you're pretty sure that the url patterns are absolutely similar to example in OP you can even simply do like

preg_match("/\d+/",$url,$matches); // where url is `http://www.xxxx.com/t1134133-mi%20&ffjfj`
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download