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. 

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.