0

Hi there how can I get only selective text in this code whith simple php parser

<div class="body" style="text-align: justify;padding: 10px;">
        <a class="entekhab_lead2" href="/"> other text : </a>
        <br> I want this text <br>
        <div align="justify"> other text or elements <div>
        <div> other text or elemnets </div>
        and anything else....
</div>

I want just return this: I want this text

I try this

foreach($html->find('div') as $element) 
   echo $element->plaintext . '<br>';

but it print every text.

2 Answers 2

1

Thats because you are selecting each div and not the br tag which is what you wanted, try this

foreach($html->find('br') as $element) 
  echo $element->plaintext . '<br>';
Sign up to request clarification or add additional context in comments.

Comments

0

An alternative approach, have a look at php strip_tags(). This function allows removing html tags with allowed argument.

ie. strip_tags($string, '<br><br/>');
implies remove all tags leaving <br>'s

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.