Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove HTML tags in PDF?

Tags:

html

php

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

like image 248
Ernyyesstt Reyes Avatar asked Aug 03 '15 03:08

Ernyyesstt Reyes


2 Answers

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!

like image 177
Bender Avatar answered Sep 27 '22 21:09

Bender


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 );
like image 27
Rohit Batta Avatar answered Sep 27 '22 21:09

Rohit Batta