Pregunta

I'm using simple_html_dom to scrap a website and it has a section like this $content =

<div id="content">

    <p>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio, voluptas, sint, accusantium, 
    </p>

    Wikipedia (Listeni/ˌwɪkɨˈpiːdiə/ or Listeni/ˌwɪkiˈpiːdiə/ wik-i-pee-dee-ə) is a collaboratively edited, multilingual, free Internet encyclopedia that is supported by <br>
    the non-profit Wikimedia Foundation. Volunteers worldwide collaboratively write Wikipedia's 30 million articles in 287 languages, including over 4.4 <br>
    million in the English Wikipedia. Anyone who can access the site can edit almost any of its articles, which on the Internet <br>

    <p>
    quidem repellendus nulla incidunt ullam?    
    </p>

</div>

But I only want the result to be like this.

Wikipedia (Listeni/ˌwɪkɨˈpiːdiə/ or Listeni/ˌwɪkiˈpiːdiə/ wik-i-pee-dee-ə) is a collaboratively edited, multilingual, free Internet encyclopedia that is supported by <br>
the non-profit Wikimedia Foundation. Volunteers worldwide collaboratively write Wikipedia's 30 million articles in 287 languages, including over 4.4 <br>
million in the English Wikipedia. Anyone who can access the site can edit almost any of its articles, which on the Internet <br>

I know the finding and fetching the content inside the #content part.I only want to know how to remove the p tag and content inside it.

Thank you.

¿Fue útil?

Solución

$content = 'hi <p> this is a test </p> hello <p> the other test </p>';

echo removeP($content);

function removeP($content){

    while(strpos($content, '<p>') != ''){

        $start = strpos($content, '<p>');
        $end = strpos($content, '</p>')+4;

        $string_being = substr($content, 0, $start);
        $string_end = substr($content, $end, strlen($content));

        $content = $string_being.$string_end;

    }

    return $content;
}

Otros consejos

To remove the p tags with simple you would do:

foreach($doc->find('p') as $p) $p->outertext = '';
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top