Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove HTML from displaying in PHP

Tags:

php

I have this text : http://pastebin.com/2Zgbs7hi

And i want to be able to remove the HTML code from it and just display the plain text but i want to keep at least one line break where there are currently a few line breaks

i have tried:

$ticket["summary"] = 'pastebin example';

$TicketSummaryDisplay = nl2br($ticket["summary"]);
$TicketSummaryDisplay = stripslashes($TicketSummaryDisplay);
$TicketSummaryDisplay = trim(strip_tags($TicketSummaryDisplay));
$TicketSummaryDisplay = preg_replace('/\n\s+$/m', '', $TicketSummaryDisplay);
echo $TicketSummaryDisplay;

that is displaying as plain text, but it shows it all as one big block of text with no line breaks at all


1 Answers

Maybe this will earn you some time.

<?php
libxml_use_internal_errors(true); //crazy o tags
$html = file_get_contents('http://pastebin.com/raw.php?i=2Zgbs7hi');
$dom = new DOMDocument;
$dom->loadHTML($html);

$result='';
foreach ($dom->getElementsByTagName('p') as $node) {
    if (strstr($node->nodeValue, 'Legal Disclaimer:')){
        break;
    }
    $result .= $node->nodeValue;

}
echo $result;
like image 89
Djonatan Avatar answered Sep 19 '26 23:09

Djonatan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!