I have :
<a href="http://abc.com">Title</a>
And :
<a href="http://xyz.com">Title</a>
I want to replace link to text “Title”, but only from http://abc.com. But I don’t know how ( I tried Google ), can you explain for me. I’m not good in PHP.
Thanks in advance.
Not sure I really understand what you’re asking, but if you :
Then, a good solution (better than regular expressions, should I say !) would be to use the DOM-related classes — especially, you can take a look at the
DOMDocumentclass, and itsloadHTMLmethod.For example, considering that the HTML portion is declared in a variable :
You could then use something like this :
And this would get you the following portion of HTML, as output :
Note that the whole
<a href="http://abc.com">Title</a>portion has been replaced by the text it contained.If you want some other text instead, just use it where I used
$tag->nodeValue, which is the current content of the node that’s being removed.Unfortunately, yes, this generates a full HTML document, including the doctype declaration,
<html>and<body>tags, …