Jump to content

Help- My code fails to convert new quotes (“foo”) to old quotes ("foo")


rwmaho

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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.