Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert this to htmlcharacters: “ and ”

We have these characters:

and

(this is not a regular ", but some sort of curly one. No idea what it is called)

When we use htmlentities(), these characters are not converted, and this causes issues later on. Further problem is that we encode our pages in Latin-1, and we can not save this particular character (so we can not do a replace-and-find, because we can not actually program this into any page).

NOTE: We DO set ENT_QUOTES, but this has no effect in htmlentities().

UPDATE

I now know they are called fancy quotes, among others, and their appropriate html entities are “ and ”. Now, the question is, why does PHP not convert these characters appropriately? See sample code:

<?php
var_dump(htmlentities($_POST['t'],ENT_QUOTES));
?>
<form action="" method="post">
<input type="t" name="t" />
<button class="button" type="submit">Send</button>
</form>

Result:

enter image description here

like image 869
user852091 Avatar asked Feb 24 '23 09:02

user852091


2 Answers

Use htmlentities() It covers all characters that have an html entity equivalent.

htmlentities

UPDATE

You need to alter the charset.

echo htmlentities("“jrod”", ENT_QUOTES, "Windows-1252");

Update 2

<?php
var_dump(htmlentities($_POST['t'],ENT_QUOTES, "Windows-1252"));
?>
<form action="" method="post">
<input type="t" name="t" />
<button class="button" type="submit">Send</button>
</form>

String used: “testing”

Var dump output: string(21) "&ldquo;testing&rdquo;"

Mind you, to see the html equivalents you have to view source as the browser renders them accordingly.

like image 93
Jrod Avatar answered Mar 02 '23 22:03

Jrod


There called “fancy quotes,” “smart quotes,” “curly quotes,” “curled quotes,” “curling quotes,” or “curved quotes”

Left Double Quotation Mark  &#8220; “
Right Double Quotation Mark &#8221; ”

You may find this link helpfull: http://www.dwheeler.com/essays/quotes-in-html.html

like image 36
Lawrence Cherone Avatar answered Mar 02 '23 21:03

Lawrence Cherone