Jump to content

Recommended Posts

The fancy-looking quotes won't insert into my DB, so I'm trying to convert them to %93 & %94 or normal quotes. 

 

Nothing I've tried works.

 

Code:

 

$fancy=" “test” ";
$fixed=htmlentities($old, ENT_QUOTES);

 

echo "fancy: $fancy<br>";

echo "fixed: $fixed";

Results:

fancy: “test”
fixed:

 

I want $fixed to be %93test%94, or even "test" would work. 

Edited by rwmaho

Does mysql_real_escape_string() work?  Also, make sure the colation (not sure if I spelt that right) supports it.  general_utf8 should be good.

Edited by Xaotique

I ran into a similar situation at one of my jobs a while back. Neither htmlentities() nor htmlspecialchars() with ENT_QUOTES would correctly handle fancy quotes. I think I ended up using str_replace() for opening and closing fancy quotes, opening and closing fancy single quotes, and something else that won't quite come to mind right now.

Edited by maxxd

Thanks.  Yes, str_replace does work. 

 

Working Code:

$fancy=" “test” ";
$fixed=str_replace("“","%93","$fancy");
$fixed2=str_replace("”","%94","$fixed");

echo "fancy: $fancy<br>";
echo "fixed: $fixed2";

 

Results:

 

fancy: “test”
fixed: %93test%94

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.