icekat83 Posted January 12, 2011 Share Posted January 12, 2011 Hey, I have a variable: 151°06'50"E This variable is giving me massive problems because of the single and double quote marks. PLEASE help me get rid of my damn t_string error! $var = 151°06'50"E; - does not work $var2 = (151°06'50"E); - does not work $var3 = ("151°06'50"E"); - does not work $var4 = ('151°06'50"E'); - does not work $var5 = addslashes("151°06'50"E"); - does not work $var6 = addslashes('151°06'50"E'); - does not work $var7 = mysql_escape_string("151°06'50"E"); - does not work $var8 = mysql_escape_string('151°06'50"E'); - does not work $var9 = htmlspecialchars("151°06'50"E"); - does not work $var10 = htmlspecialchars('151°06'50"E'); - does not work $var11 = urlencode("151°06'50"E"); - does not work $var12 = urlencode('151°06'50"E'); - does not work I've also tried the three functions with the various enclosing quote marks (single and double). I've also tried string replace. At the moment I'll settle for being able to put: echo $var; and NOT have an error. Please help...this error is driving me nuts!!! IceKat. Quote Link to comment https://forums.phpfreaks.com/topic/224152-quote-marks/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 12, 2011 Share Posted January 12, 2011 t_string error That's a php parse error because your data string contains quotes that break the php string syntax. For typing that data literally into your php code, whatever overall start/end quote type is being used, must be escaped when it occurs inside of the string. The following two variations work - <?php $var = "151°06'50\"E"; echo $var; $var4 = '151°06\'50"E'; echo $var4; ?> Quote Link to comment https://forums.phpfreaks.com/topic/224152-quote-marks/#findComment-1158243 Share on other sites More sharing options...
icekat83 Posted January 12, 2011 Author Share Posted January 12, 2011 I know in this case I can manually put in slashes but with the way the data is coming in I can't always do that so I need an automated version which I would have thought I could have but can't work out. Thanks all..... IceKat. Quote Link to comment https://forums.phpfreaks.com/topic/224152-quote-marks/#findComment-1158244 Share on other sites More sharing options...
PFMaBiSmAd Posted January 12, 2011 Share Posted January 12, 2011 You would need to be more specific about where you are getting the data from and where you are using the data. We only see the information you supply in your post and for the error message you hinted at, that can only occur when you have the value literally entered in a php statement. When that value comes from a form or reading some data into a variable, you won't be getting php parse errors. Quote Link to comment https://forums.phpfreaks.com/topic/224152-quote-marks/#findComment-1158245 Share on other sites More sharing options...
icekat83 Posted January 12, 2011 Author Share Posted January 12, 2011 A break for dinner (it's 7pm where I am) has made me realise that DUH....of course. Brain dead moment gratefully solved. Thanks guys. IceKat. Quote Link to comment https://forums.phpfreaks.com/topic/224152-quote-marks/#findComment-1158253 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.