regex - Php Regular Expression to Replace href=“URL” to onclick=myfunction(URL) -


With Php, I want to convert all the links to the Javascript function, for example:

From: & lt; A href = "URL" & gt; ABC & lt; / A & gt;

to

ex> $ doc = new DOMDocument (); $ Doctor & gt; LoadHTML ($ HTML); Foreach ($ doc-> getElementsByTagName ('a') as $ elem) {if ($ elem-> hasativity ('href')) {$ elem- & gt; Set attribute ('onclick', 'some function (' .json_encode ($ elem-> getAttribute ('href')) ')'). $ Elem-> RemoveAttribute ('href'); }}

Comments