...

View Full Version : Help htmlentities not working



franzlin2010
11-04-2010, 07:50 PM
Hi all,

I have been trying to use the htmlentities() function to convert some text but its not working for me

here are some of my trials



$orig = "!@#$%^&*()<>,";

echo htmlentities($orig);

echo htmlspecialchars($orig);

// It returns the same strings !@#$%^&*()<>", without converting the string

Please could it be some configuration problem?

MattF
11-04-2010, 07:53 PM
If you're echoing that output in a html page, everything will appear the same. Viewing the source is the only way to check the changes. If you're running that script from the commandline, it should encode the <>& characters on output at least.

franzlin2010
11-04-2010, 08:21 PM
Thank you very much senoir coder for you fast and quick reply
I am very grateful,
it has solved m problem

The problem i am encountering really is that i am trying to insert some records into a database and the contents contains some apostrophes when i insert it into the database, it shows some unknown characters for me


$string1 = "In today’s high speed"; // please take not of the inverted commas

$string1 = "In today's high speed";// please take not of the inverted commas

When i insert the two into the database with the mysql_real_escape function
The first string is not escaped while but gives me some unknown texts

while the second string is escaped correctly, is there difference between the two inverted commas?

MattF
11-04-2010, 08:40 PM
while the second string is escaped correctly, is there difference between the two inverted commas?

Yes. The second one, ' is a special character where SQL is concerned, hence needs to be escaped. The first is not, so will be inserted as is. The unknown text you are seeing is most likely its ASCII value or suchlike:

http://www.asciitable.com/

Dormilich
11-05-2010, 08:56 AM
the first one is the "right single quotation mark". you need UTF-8 to display it correctly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum