How to differentiate tags in single Div when parsing HTML via simple_html_dom in PHP -


I am using simple_html_dom in PHP to parse an HTML page But I found the stock in the following situation. I have a diva selector that has a nested span

  & lt; Div class = "name1" & gt; In Text1, commas and lt; Span class = "name2" & gt;, Text2 & lt; / Span & gt; & Lt; / Div & gt;  

When I use the following code:

  foreach ($ html-> search ('div [class = name1]') $ Text = $ result- & gt; Xmltext;  

Then I get a string:

  "Lesson 1, comma, text2"  

because Both are part of "text1, comma" and "text2" div, which has 'class = name1'

what I want "different text of text 1, comma" and "text2" I am able to extract "text2" from it using a nested match, but I can not just remove "lesson 1".

with $ text1 = "text1, comma, text2" and With $ text2 = ", Text2" you can use substr_replace () :

  $ text1 = substr_replace ($ text) 1, '', - (string ($ text2));  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -