php - JavaScript regular expression to replace HTML anchors -



php - JavaScript regular expression to replace HTML anchors -

i got html string , want convert special tags else. need tinymce plugin. tried alter wordpress wpgallery plugin.

for example: these in html string

<a href="http://www.yahoo.com">yahoo</a> <a href="http://www.google.com">google</a> <a href="#" rel='special' title='link cat_id="4" content_id="5" content_slug="slug 1"'>some else</a>

here have find special link 1 , convert else it's title value like:

{link cat_id="4" content_id="5" content_slug="slug 1"}

i need homecoming value insert mysql

<a href="http://www.yahoo.com">yahoo</a> <a href="http://www.google.com">google</a> {link cat_id="4" content_id="5" content_slug="slug 1"}

i tried

function getattr(s, n) { n = new regexp(n + '="([^"]+)"', 'g').exec(s); homecoming n ? tinymce.dom.decode(n[1]) : ''; }; homecoming co.replace(/[^<]*(<a href="([^"]+)">([^<]+)<\/a>)/g, function(a,im) { var cls = getattr(im, 'rel'); if ( cls.indexof('special') != -1 ) homecoming '{'+tinymce.trim(getattr(im, 'title'))+'}'; homecoming a; });

this

/[^<]*(<a href="([^"]+)">([^<]+)<\/a>)/g

does not find tags rel eq 'special' others.

you might want domdocument , related classes. much improve @ parsing html homebrewed regex solution be.

you can create domdocument using supplied markup, execute getelementsbytagname hyperlinks, scan attributes rel attribute value of special, , take appropriate action.

php javascript regex

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -