rwmaho Posted October 18, 2014 Share Posted October 18, 2014 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. Link to comment https://forums.phpfreaks.com/topic/291915-help-my-code-fails-to-convert-new-quotes-%E2%80%9Cfoo%E2%80%9D-to-old-quotes-foo/ Share on other sites More sharing options...
codefossa Posted October 18, 2014 Share Posted October 18, 2014 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. Link to comment https://forums.phpfreaks.com/topic/291915-help-my-code-fails-to-convert-new-quotes-%E2%80%9Cfoo%E2%80%9D-to-old-quotes-foo/#findComment-1494112 Share on other sites More sharing options...
rwmaho Posted October 18, 2014 Author Share Posted October 18, 2014 > Does mysql_real_escape_string() work? It didn't help. > general_utf8 should be good My database's collation is "general_utf8_ci" Link to comment https://forums.phpfreaks.com/topic/291915-help-my-code-fails-to-convert-new-quotes-%E2%80%9Cfoo%E2%80%9D-to-old-quotes-foo/#findComment-1494113 Share on other sites More sharing options...
maxxd Posted October 18, 2014 Share Posted October 18, 2014 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. Link to comment https://forums.phpfreaks.com/topic/291915-help-my-code-fails-to-convert-new-quotes-%E2%80%9Cfoo%E2%80%9D-to-old-quotes-foo/#findComment-1494122 Share on other sites More sharing options...
rwmaho Posted October 18, 2014 Author Share Posted October 18, 2014 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 https://forums.phpfreaks.com/topic/291915-help-my-code-fails-to-convert-new-quotes-%E2%80%9Cfoo%E2%80%9D-to-old-quotes-foo/#findComment-1494126 Share on other sites More sharing options...
maxxd Posted October 19, 2014 Share Posted October 19, 2014 It's brute force, but glad it worked for you. Link to comment https://forums.phpfreaks.com/topic/291915-help-my-code-fails-to-convert-new-quotes-%E2%80%9Cfoo%E2%80%9D-to-old-quotes-foo/#findComment-1494165 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.