anchor - How do I prevent Php's DOMDocument from encoding html entities? -
I have a function that replaces the href attribute of anchor in a string using php's DOMDocument. Here's a snippet:
$ doc = new DOMDocument ('1.0', 'UTF-8'); $ Doctor & gt; LoadHTML ($ text); $ Anchors = $ doc- & gt; GetElementsByTagName ('A'); Forex Currency ($ Angers $ A) {$ a- & gt; Set attribute ('href', 'http://google.com'); } Return $ doc- & gt; Save HTML (); The problem is that HTML ($ text) is surrounded by $ text in dotcom, html, body, etc. Instead of loading it instead of HTML (), try to work on it:
$ doc = new DOMDocument ('1.0', 'UTF-8'); $ Node = $ doc- & gt; CreateTextNode ($ text); $ Doctor & gt; AppendChild ($ node); ... Unfortunately, it encodes all the entities (including anchors). Does anyone know how to close it? I have already seen well through the doctors and tried to hack it, but could not understand it.
Thank you! :)
$ text place-holder is a translated string with anchor tag
If holders with these place have a strict, well-defined format, then one can be simple or trick.
I generally do not suggest negligible about HTML documents with regex, but they are suitable for a small well-defined subtitle.
Comments
Post a Comment