PHP替换和删除?

时间:2011-04-29 16:07:45

标签: php replace string

我有随机的产品链接网址。

我想要结果Like>

http://yourdomain.com/index.php?main_page=product_info&products_id=5 产品编号= 5 要么 http://yourdomain.com/index.php?main_page=product_info&products_id=3210:cdfa96a858cdde666a79b09207528297 产品编号= 3210

先谢谢

1 个答案:

答案 0 :(得分:2)

$string = "http://yourdomain.com/index.php?main_page=product_info&products_id=5";
$pattern = "/products_id=(\d+)/";
preg_match($pattern, $string, $matches);
$out = "Product Id = ".$matches[1];