I would like to add root path of the site for those anchor tag which have not root path using php dom document, Till now a have made a function to do this with str_replace function but for some links its adding three and for times root path. Then what i should to edit in this function.
Problem:= The problem is its adding three and for times root path for every anchor tag, and not for some.
$HTML variable has many anchor tags, about above 200 links.
And also same for images.
I know that its very dirty question, but what i have missed, i cant getting.
function addRootPathToAnchor($HTML)
{
$tmpHtml = '';
$xml = new DOMDocument();
$xml->validateOnParse = true;
$xml->loadHTML($HTML);
foreach ($xml->getElementsByTagName('a') as $a )
{
$href = $a->getAttribute('href');
if(strpos($href,'www' > 0))
continue;
else
$HTML = str_replace($href,"http://www.mysite.com/".$href,$HTML);
}
return $HTML;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…