vendredi 27 mai 2016

Replace words in HTML string by spans with title, except within certain tags

I looked around anywhere but I did not find a decent solution for this.

I have an HTML string:

$html = "<p>This an example string with a <a href="/link/to/example" title="Title to example">link</a> and an <img src="path/to/example-image.jpg" alt="Alt text from example image"></p>"

I have an array:

$glossary = array(
    "example" => "<span class='tooltip'>This is the explanation</span>"
    ...
)

What I try to achieve is to replace the string 'image' in the html string without changing it in the IMG and A elements, basically all the elements in the exclude array:

$excludes = array('img','a',etc)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire