我想在我解析的html中更改特定链接的URL结尾。在以前的场合我使用过这段代码
$html = file_get_html('URL');
// search for .htm change to .php
foreach ($html->find("td a") as $a) {
$a->href = substr_replace($a->href, 'php', -3);
但它会改变所有链接。我现在要区分特定的URL。我只想更改那些不包含" box"在它的链接。
Example:
thisismyboxlink123.htm --> no change of ending please
thisismyotherlink123.htm --> thisismyotherlink123.php
答案 0 :(得分:1)
您可以使用strpos()
检查字符串printf("%d", bitcounts[2]); //2
是否在链接中。如果不是("box"
),您可以替换它:
===false