Reputation: 300
I am retrieving text data from a database which includes bullets and newlines. I have successfully removed the newlines and converted them to <br />
using the nl2br()
function in PHP, but the bullets act weird and display "•" instead of "•" (see screenshot).
I have tried using htmlspecialchars()
function in PHP but it still displays the same output.
Upvotes: 1
Views: 3910
Reputation: 4752
The Unicode character U+2022 (BULLET)
is encoded in UTF-8 as the octets E2
80
A2
. If your page contains these octets, and the page is incorrectly interpreted using a different character encoding, such as Windows-1252, the resulting page will display the three characters â
, €
, ¢
.
To properly display the bullet character, you need to declare the correct character encoding for your document:
header ('Content-Type: text/html; charset=utf-8');
If it is not feasible to use the UTF-8 encoding, you can convert the string using htmlentities()
, which should convert the bullet characters, and other undisplayable characters, into HTML character references (•
):
$s = "Bullet \xe2\x80\xa2 character";
echo htmlentities ($s), "\n";
Or, if PHP's character encoding is not configured correctly:
$s = "Bullet \xe2\x80\xa2 character";
echo htmlentities ($s, ENT_NOQUOTES, 'utf-8'), "\n";
Upvotes: 0
Reputation: 300
I have used htmlentities()
now instead of htmlspecialchars
. I have solved my own problem but I hope this thread will help others in the future.
Upvotes: 3