I need to insert the string directly after the open anchor ends (where the anchor material is started).
Here's my code:
& lt; Ul id = "menu-topmenu2" class = "menu" & gt; & Lt; Li id = "menu-item-5" class = "menu-item menu-item-type-post_type menu-item-5" & gt; & Lt; A href = "http: //localhost/domain/barnlager.se/?page_id=2" & gt; & Lt; / A & gt; About & lt; / Li & gt; & Lt; Li id = "menu-item-5" class = "menu-item menu-item-type-post_type menu-item-5" & gt; & Lt; A href = "http: //localhost/domain/barnlager.se/?page_id=2" & gt; Services & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt;
In this example, do I need to have a small regexp content about "about" and "services"? The HTML code above can be a string called $ $ content.
I use PHP, thank you!
For example, I use parser, DOM:
$ Content = '... your HTML string ...'; $ Doc = new DOMDocument (); $ Doctor & gt; LoadHTML ('& lt; html & gt; & lt; body & gt;' $ content. '& Lt; / body & gt; & lt; / html & gt;'); $ X = new DOMXPath ($ doc); Foreach ($ x-> Query ('/ a') as an anchor) {// strrev (trim ($ anchor-> node vane)) is just an example you would like anything $ anchor - & gt; InsertBefore (new DomText (strave (trim ($ anchor- & gt; node value)), $ anchor-> first hair); Echo $ doc- & gt; Save XML ($ doc- & gt; getElementsByTagName ('ul') - & gt; Items (0));
And as an additional bonus, it throws a warning defined twice in your HTML id = "menu-item-5"
, which is valid is not. / P>
Comments
Post a Comment