Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does </p> mean in query results?

Tags:

html

php

mysql

Ok, I run a simple query,

SELECT description 
FROM TABLE
WHERE id = 111;

in my results, I get:

<p>Blah blah description is here blah blah<p>

Then when I output my results with PHP using:

echo '<ul>' . $row['description'] . '</ul>';

I get this on my html page:

<p>Blah blah description is here blah blah</p>

How can I get rid of the <p> tags at the beginning and end of my description? I am using concrete5 for my page if that helps. Thanks!

like image 268
user2232926 Avatar asked Dec 12 '22 11:12

user2232926


2 Answers

You can use strip_tags to get rid of HTML.

$string = "&lt;p&gt;Blah blah description is here blah blah&lt;p&gt;";
$string = html_entity_decode($string);
$string = strip_tags($string);
echo $string; // Blah blah description is here blah blah

You shouldn't typically store HTML in the database though. Unless the input is coming from a source like a WYSIWYG you will want to store plaintext. This smells like a case where plaintext was needed.

like image 129
Halcyon Avatar answered Dec 14 '22 00:12

Halcyon


Those are encoded html entities. to get rid of them you may do this:

echo strip_tags(html_entity_decode($yourString));
like image 28
0x_Anakin Avatar answered Dec 14 '22 00:12

0x_Anakin