Jump to content

HTMLSPECIALCHARS / HTMLENTITIES Displaying problems


Beauford

Recommended Posts

I have a form where users enter info. I have a user with a username that's supposed to looks like this:

 

ΠIGHTMΛΓΣZ BΛY BΛY®

 

When I display it it looks like this:

 

ΠIGHTM��ΣZ B�Y B�Y®

 

I am inserting it into the Mysql DB with this:

 

$msg = htmlspecialchars(mysql_real_escape_string($_POST['message']), ENT_QUOTES);

 

When retrieving and displaying it I use:

 

$message = nl2br($r['mail_text']);

 

Can someone set me straight on this at it has been causing me nightmares for quite some time, this is just the latest in a line of problems with trying to display things properly.

 

Thanks

 

Link to comment
Share on other sites

I have a form where users enter info. I have a user with a username that's supposed to looks like this:

 

ΠIGHTMΛΓΣZ BΛY BΛY®

 

When I display it it looks like this:

 

ΠIGHTM��ΣZ B�Y B�Y®

 

I am inserting it into the Mysql DB with this:

 

$msg = htmlspecialchars(mysql_real_escape_string($_POST['message']), ENT_QUOTES);

 

When retrieving and displaying it I use:

 

$message = nl2br($r['mail_text']);

 

Can someone set me straight on this at it has been causing me nightmares for quite some time, this is just the latest in a line of problems with trying to display things properly.

 

Thanks

 

I had similar problems. I was using Slavic symbols ŠĐČĆŽ ...

All problems have gone when I started using UTF-8 encoding in database, HTML and PHP.

You can solve this without UTF by making all encodings equal.

Link to comment
Share on other sites

This is the most ridiculous thing I have ever seen. Now my BBCodes don't work and apostophes are all screwed up.  I can't believe you have to jump though hoops just to get something to display the way it should. It Just amazes me.

 

Does anyone have any ideas, or should I just start looking for a language that does this by default, which it should in the first place.

 

Just a little frustrated with this as it's been months trying to get everything to work right.

 

Thanks

Link to comment
Share on other sites

I'm going to take one last stab at this to see if anyone knows how to get this working. I am at my wits end with this and will have no choice but to dump PHP and MySQL and see if there is something else that actually works with out all the cloack and dagger.

 

I have spent the last two days on this, over 20 hours and I'm nowhere.

 

Simply put, I want things that go into the database to display the same when I retrieve them. The biggest problem I have is an apostrophe, which just seems so stupid wasting this much time for one character.

 

Finish in next post. LOL

Link to comment
Share on other sites

I am using mysql_real_escape_string when I input text and have tried a variety of ways when trying to display it.

 

The biggest problem is whenever a user tries to edit their post, anything after an apostrophe is missing,

 

I have tried stripslashes(htmlentities($_POST['stuff'],ENT_QUOTES)) or just stripslashes, or just htmlentities.

 

What am I doing wrong, this can't be this complicated????????

 

Thanks

Link to comment
Share on other sites

Getting shrill, and blaming all your problems on PHP isn't going to help you.  This is not a PHP issue.  My advice to you is that you need to invest some time understanding character sets, as well as web entitities.  dzelenika already provided one suggestion for how to handle the problem, and you didn't respond to him at all.

 

We don't have much in the way of information to go on.  You only posted two lines of code in your original message, and we have no information about what exactly is malfunctioning in whatever your current code looks like. Right off the bat, I can tell you that htmlspecialchars() only takes care of a handful of special characters, so you probably want to look at htmlentities() instead.

 

With that said:

 

- What is the character set of the page that contains the form that accepts the submission

- What is the character set for the mysql table where the data is being stored

- What is the character set for the page where you display the data that has been fetched from the db

 

Where is the relevant code, and where is an example of your results.

 

Given these things, perhaps we can help.  ;)

 

 

Link to comment
Share on other sites

I am using mysql_real_escape_string when I input text and have tried a variety of ways when trying to display it.

 

The biggest problem is whenever a user tries to edit their post, anything after an apostrophe is missing,

 

I have tried stripslashes(htmlentities($_POST['stuff'],ENT_QUOTES)) or just stripslashes, or just htmlentities.

 

What am I doing wrong, this can't be this complicated????????

 

Thanks

 

Probably the missing piece to the puzzle for you is html_entity_decode().  I don't know why you would be doing stripslashes.  That's only something you would use if you had previously used addslashes, which you shouldn't be.  Again, you need to be aware of your character sets.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.