我有这段代码可以输出所有网址 ?tid=someNumbers
<?php
include 'simple_html_dom.php';
// Create DOM from URL or file
$html = file_get_html('http://news.sinchew.com.my/node');
// Find all links
foreach($html->find('a') as $element) {
$tid = '?tid';
$url = 'news.sinchew.com.my/node';
if(strpos($element->href,$tid) && (strpos($element->href,$url))) {
echo $element->href . '<br>';
}
}
?>
我想做的是更改?tid=someNumbers
为?tid=1234
,然后使用输出所有url ?tid=1234
。我在这里呆了几个小时,有人可以帮我吗?
尝试preg_replace
根据正则表达式执行替换:
<?php
//...
echo preg_replace("/\\?tid=[0-9]+/", "?tid=1234", $element->href);
//...
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句