nelliza111 Posted January 19, 2011 Share Posted January 19, 2011 I am trying to do the seemingly simple thing - replace all single quotes in text str_replace ("'", "´", $text); It does not replace anything. I trying escaping single quote, using other similar functions - nope. Also tried to google What I an doing wrong? Any help would ne much appreciated. Quote Link to comment Share on other sites More sharing options...
Maq Posted January 19, 2011 Share Posted January 19, 2011 It works for me. You do you know that the entity ´ is ´ when parsed by the browser? Run the script in CLI, you'll see the actual entity. If that doesn't work we need to see more of your script. Here is what I did: ini_set ("display_errors", "1"); error_reporting(E_ALL); $text = "asdfasdf'asdf"; $replace = str_replace ("'", "´", $text); echo $replace; ?> CLI: asdfasdf´asdf Web: asdfasdf´asdf Quote Link to comment Share on other sites More sharing options...
nelliza111 Posted January 20, 2011 Author Share Posted January 20, 2011 The line of code is in function that works perfectly except for single quote line function convert_quotes ($text) { $text = ereg_replace ('"', """, $text); $text = str_replace ("'", "´", $text); $text = ereg_replace ('“', "“", $text); $text = ereg_replace ('”', "”", $text); $text = ereg_replace ('‘', "‘", $text); $text = ereg_replace ('’', "’", $text); $text = ereg_replace ('«', "«", $text); $text = ereg_replace ('»', "»", $text); return $text; } I have standard CentOS built, did not edit php.ini. I have not the slightest clue what could be wrong here. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted January 20, 2011 Share Posted January 20, 2011 did you run the script via command line, as suggested by Maq? if you are viewing the output with a browser you might be seeing the browser-interpreted code. Quote Link to comment Share on other sites More sharing options...
nelliza111 Posted January 20, 2011 Author Share Posted January 20, 2011 did you run the script via command line, as suggested by Maq? if you are viewing the output with a browser you might be seeing the browser-interpreted code. I need the browser-interpreted code exactly - to replace single quote in html code output. It does not matter how it works from command line. And yes, all browsers show the same - not replaced single quote. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 20, 2011 Share Posted January 20, 2011 Did you look at the output in View ---> Source to see what is actually there, or are you just going by what the browser renders? Quote Link to comment Share on other sites More sharing options...
nelliza111 Posted January 20, 2011 Author Share Posted January 20, 2011 Of course I did look at source. Also searched the web, read FAQ and manuals at php.net before posting. it is not something obvious. Quote Link to comment Share on other sites More sharing options...
parino_esquilado Posted January 20, 2011 Share Posted January 20, 2011 Try htmlspecialchars() Quote Link to comment Share on other sites More sharing options...
TOA Posted January 20, 2011 Share Posted January 20, 2011 I noticed that it's the only one that's not preg_replace...any special reason? Quote Link to comment Share on other sites More sharing options...
nelliza111 Posted January 20, 2011 Author Share Posted January 20, 2011 Try htmlspecialchars() Tried. Single quote is not converted anyway. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted January 20, 2011 Share Posted January 20, 2011 when i run the same code I get this in the source, also displays correct in browser "\´\“"\”\‘\’\«\» Quote Link to comment Share on other sites More sharing options...
nelliza111 Posted January 20, 2011 Author Share Posted January 20, 2011 I noticed that it's the only one that's not preg_replace...any special reason? Tried all functions I can think of, including preg_replace, ereg_replace - no way. Quote Link to comment Share on other sites More sharing options...
nelliza111 Posted January 20, 2011 Author Share Posted January 20, 2011 when i run the same code I get this in the source, also displays correct in browser "\´\“"\”\‘\’\«\» Could it be something in php.ini that prevents the quote from being converted? Quote Link to comment Share on other sites More sharing options...
nelliza111 Posted January 20, 2011 Author Share Posted January 20, 2011 I put up php_info page - maybe someone could see something special there http://maidan.org.ua/test.php Quote Link to comment Share on other sites More sharing options...
Maq Posted January 20, 2011 Share Posted January 20, 2011 AFAIK, there is nothing in the php.ini that would prevent replacing single quotes, but maybe there is. Can we see an exact sample text that you're passing in? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.