Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output "<"/">" Character in HTML

I'm trying to display "<"/">" as String in HTML not as a tag.

I have a database that contains user's Fullname and Email and when I want display them both I have a format like this:

Christian Eric Paran <[email protected]>

but I it only display like this:

Christian Eric Paran

is there a way to Display this in HTML from PHP?

like image 880
Christian Eric Paran Avatar asked Sep 09 '26 12:09

Christian Eric Paran


2 Answers

Represent characters with special meaning (<&lt; & &&amp; being the ones you need to worry about in text nodes) in HTML using character references.

The htmlspecialchars function will convert for you.

print htmlspecichars("Christian Eric Paran <[email protected]>");
like image 188
Quentin Avatar answered Sep 11 '26 03:09

Quentin


Problem is, the < and > are used by HTML to delimit tags. The email address thus ends up parsed as an HTML tag, and ends up hidden by most if not all browsers.

Use &lt; to display a < in HTML, and &gt; for >.

If the data will be dynamic, use htmlentities or htmlspecialchars to do the above encoding for you prior to printing it.

like image 31
cHao Avatar answered Sep 11 '26 03:09

cHao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!