Get database text by ignoring tags

0

Good morning,

I have some saved articles in a database, where all the tags appear so that when you download it with PHP you can load all the elements,

...

The fact is that a preview of the article I just want it to be plain text. I have tried 2 options but none of them gives me the result I want:

echo "<p>" . htmlspecialchars(substr($articulos[$i]['articulo'], 0, 300)) . "...</p>";

In this case, it returns all the text in the database with the tags, without converting the text to HTML code.

echo "<p>" . substr($articulos[$i]['articulo'], 0, 300) . "...</p>";

In this other case it converts the HTML tags, but if there are tags at the beginning of the article, they appear and distort everything ...

The only thing I can think of is that the first 300 characters of the articles are text with the tag

, but I would like to know if there is any way to save this problem.

    
asked by JetLagFox 06.02.2017 в 23:06
source

1 answer

3

The function you need is strip_tags () . This function eliminates the HTML and PHP tags of a text, it also supports parameters to eliminate all the tags except for some specific ones.

link

    
answered by 06.02.2017 / 23:14
source