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

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -