Ernyyesstt Reyes
Ernyyesstt Reyes

Reputation: 69

How to remove HTML tags in PDF?

How to remove the HTML tags?

I want to remove the HTML tags in the PDF view. Look at the picture below. Please help me with this.

This is my code:

$string1 = $_POST["editor1"];
$string1 = str_replace("<p>", "", $string1);
$string2 = str_replace("&nbsp; ", " ", $string1);
$string2 = explode("</p>", $string1);

This is my output:

foreach ($string2 as $key) {
    $pdf->Multicell(0,3,$key);
}

?>

my pdf file

Upvotes: 6

Views: 3635

Answers (3)

Jakir Hosen Khan
Jakir Hosen Khan

Reputation: 1528

strip_tags() is the best way. str_replace() required more code.

Upvotes: 0

Bender
Bender

Reputation: 715

The strip_tags() function strips a string from HTML, XML, and PHP tags.

strip_tags(string,allow)

$string1 = strip_tags($string1);

*Update

-Allowing certain tags to be get printed.

echo strip_tags("Hello <b><i>SO!</i></b>","<b>");

prints Hello SO!

Upvotes: 6

Rohit Batta
Rohit Batta

Reputation: 482

You could use following code for replacement of special characters in pdf formatted text. I have used this code in my java project, and it is working fine there. I have changed this to php for you.

    $string1=str_replace("&nbsp", " ", $string1 );
    $string1=str_replace("&", "&amp;", $string1 );
    $string1=str_replace(">", "&gt;", $string1 );
    $string1=str_replace("<", "&lt;", $string1 );
    $string1=str_replace("&agrave;", "&#192;", $string1 );
    $string1=str_replace("&euml;", "&#203;", $string1 );
    $string1=str_replace("\"", "&quot;", $string1 );
    $string1=str_replace("&lt;br /&gt;", "<br />", $string1 );
    $string1=str_replace("&eacute;", "&#233;", $string1 );
    $string1=str_replace("à", "&#224;", $string1 );

Upvotes: 2

Related Questions