Reputation: 59
On the basis of data I have saved an article that comes with HTML as <br>, <table> ... etc. ....
example :
<tr>
<td style="width:50%;text-align:left;">Temas nuevos - Comunidad</td>
<td class="blocksubhead" style="width:50%;text-align:left;">Temas actualizados - Comunidad Temas actualizados - Comunidad</td>
</tr>
What I want is displayed on another screen a summary of the article using substr (), my problem is I can not print what I want, and that prints the html code eta first.
Example: echo substr($row["news"], 0, 20);
It is printing the first 20 characters, it only show at browser:
<td style="width:50%;text-align:l<td/>
What I want is, it only show the text and discard the html code it has
Upvotes: 0
Views: 791
Reputation: 9583
The strip_tags() function strips a string from HTML, XML, and PHP tags.
//remove the html from the string.
$row["news"] = strip_tags($row["news"]);
//getting the first 20 character from the string and display as output.
echo substr($row["news"], 0, 20);
Upvotes: 0
Reputation: 8616
Use strip_tags()
to strip html etc from the string...
So: echo substr(strip_tags($row["news"]), 0, 20);
http://php.net/manual/en/function.strip-tags.php
You could also do it using preg_replace()
to match and replace anything that looks like a tag :)
Upvotes: 1