I load a html page with PHP Dom Document :
$doc = new DOMDocument();
@$doc->loadHTMLFile($url);
I search in my page all "a" elements, and if they realize my condition i need to replace for example <a href="blablablabla">My link is beautiful</a> by just My link is beautiful
Here my loop :
$liens = $div->getElementsByTagName('a');
foreach($liens as $lien){
if($lien->hasAttribute('href')){
if (preg_match("/metz2/i", $lien->getAttribute('href'))) {
//HERE I NEED TO REPLACE </a>
}
$cpt++;
}
}
Do you have any ideas ? Suggestions ? Thanks 🙂
Every time i need to manage DOM with PHP, i use a framework called PHP Simple HTLM DOM parser. (Link here)
It’s very easy to use, something like this might work for you: