shadiadiph Posted May 3, 2010 Share Posted May 3, 2010 I have been messing with this for hours now with no joy how can I str_replace("'","'",$var); so it writes ' or chr(39) to a file I have been trying for hours but it seems to replace ' a writes it as a ' ? not ' ?????????????? Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/ Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 you sure it's not a back tick? Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1052708 Share on other sites More sharing options...
shadiadiph Posted May 3, 2010 Author Share Posted May 3, 2010 'a writes it' should be and writes it as a sorry bit out of it right now you sure it's not a back tick? ???????????????????????????????????????????? Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1052710 Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 you get a single quote ( ' ) and you get a back tick ( ` ) subtle difference to the eye, but could be all it takes to throw your str_replace out. Incidently, would you mind telling us why you need to str_replace this, there may be alternatives. Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1052712 Share on other sites More sharing options...
shadiadiph Posted May 3, 2010 Author Share Posted May 3, 2010 Ok here is the reason I have made some code to turn the maxminds geocountry lite csv file in to an SQL file the. Reason I need to replace ' and also I need to replace , to an HTML code is because of those annoying country names like 'Korea', republic of' SQL seperates everythig by a ' and a , so i need to replace some ''s with an HTML code Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1052725 Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 I know there is a better way of doing it than swaping out the character, but I can't remember how it's done at the moment. In about 9 ours I'll be back at my development machine, I should have some stock code I can post that does something similar to what you are trying. I do hope however that someone else has the answer on how to set the sql_escape_character to somthing different. Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1052733 Share on other sites More sharing options...
shadiadiph Posted May 3, 2010 Author Share Posted May 3, 2010 Thanks I am sure there must be a way to replace a ' with the HTML alternative if there isn't then there. Is a serious glitch in php you can str_replace a " with the html chr() why not the ' also! Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1052739 Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 you could try escaping it $quote = '\''; str_replace($quote,''',$var); Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1052742 Share on other sites More sharing options...
shadiadiph Posted May 4, 2010 Author Share Posted May 4, 2010 mm didn't work but thanks for trying Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1052939 Share on other sites More sharing options...
nhojeinnor Posted May 4, 2010 Share Posted May 4, 2010 you could try escaping it $quote = '\''; str_replace($quote,''',$var); str_replace('$quote',','$var'); here try this. this should work.. Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1052944 Share on other sites More sharing options...
shadiadiph Posted May 4, 2010 Author Share Posted May 4, 2010 mm still can't fina a way to do it at the moment i am trying to go around it a different way by replaceing intances of commaspace ", " with ,space but cant seem to get this working either Quote Link to comment https://forums.phpfreaks.com/topic/200608-str_replace-problem/#findComment-1053160 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.