Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't strip_tags work in PHP?

Tags:

I've got the following code:

<?php echo strip_tags($firstArticle->introtext); ?> 

Where $firstArticle is a stdClass object:

object(stdClass)[422]   public 'link' => string '/maps101/index.php?option=com_content&view=article&id=57:greenlands-newest-iceberg&catid=11:geography-in-the-news' (length=125)   public 'text' => string 'GREENLAND'S NEWEST ICEBERG' (length=26)   public 'introtext' => string '<p>A giant chunk of ice calved off the Petermann Glacier on      the northwest side of Greenland this summer. At nearly 100 square miles (260      sq. km) in size, four times the size of Manhattan, th' (length=206)   public 'date' =>      object(JDate)[423]       public '_date' => int 1284130800       public '_offset' => int 0       public '_errors' =>          array           empty 

You can see that $firstArticle->introtext refers to the string:

"<p>A giant chunk of ice calved off the Petermann Glacier on the northwest side of Greenland this summer. At nearly 100 square miles (260 sq. km) in size, four times the size of Manhattan, th"

The <p> tag is a problem for me in this application, however strip_tags absolutely refuses to remove it and I can't figure out why. I actually gave up on strip_tags and attempted to do a preg_replace instead with the regex /<(.|\n)*?>/ :

preg_replace('/<(.|\n)*?>/', '', $firstArticle->introtext); 

But that didn't work either! How can I strip all HTML tags (matched or not) from this string when I output it?

like image 920
rushinge Avatar asked Sep 23 '10 17:09

rushinge


People also ask

What is Strip_tags function in PHP?

The strip_tags() function is an inbuilt function in PHP which is used to strips a string from HTML, and PHP tags. This function returns a string with all NULL bytes, HTML, and PHP tags stripped from a given $str. Syntax: string strip_tags( $str, $allowable_tags )

How do you escape HTML tags in PHP?

Definition and UsageThe strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow parameter.

Is it possible to remove the HTML tags from data?

Strip_tags() is a function that allows you to strip out all HTML and PHP tags from a given string (parameter one), however you can also use parameter two to specify a list of HTML tags you want.

How do I remove HTML tag from string in Wordpress?

wp_strip_all_tags is a built in wordpress function. Which is used to strip out tags from the given strings. It is a modified function of PHP strip_tags function or an extended version. strip_tags function is used to remove HTML and PHP tags from strings.


1 Answers

try:

<?php echo strip_tags(html_entity_decode($firstArticle->introtext)); ?> 
like image 148
The Surrican Avatar answered Sep 29 '22 13:09

The Surrican