qmqmqm Posted February 17, 2009 Share Posted February 17, 2009 Hi I have a string that contains "my_value" (including the double-quotation matks). How should I trim off the 2 double quotation marks? I used trim($myString, "\""); but it only got rid of the first double-quotation mark... Thanks, Tom Quote Link to comment https://forums.phpfreaks.com/topic/145594-php-string-trimming/ Share on other sites More sharing options...
premiso Posted February 17, 2009 Share Posted February 17, 2009 <?php $trim = '"test string"'; $trim = trim($trim, '"'); echo $trim; ?> That worked for me. EDIT: Thinking about it, are Magic Quotes turned on, on your server? If so then the character is actualy \" which would explain why it does not trim it. I would either turn off Magic Quotes or try doing a stripslashes on the data before trimming. This is assuming you are getting the value from a POST/GET scenario. Quote Link to comment https://forums.phpfreaks.com/topic/145594-php-string-trimming/#findComment-764369 Share on other sites More sharing options...
allworknoplay Posted February 17, 2009 Share Posted February 17, 2009 This works for me: <?php $string = trim('"string"', "\""); echo $string; ?> Output: string Quote Link to comment https://forums.phpfreaks.com/topic/145594-php-string-trimming/#findComment-764370 Share on other sites More sharing options...
cooldude832 Posted February 17, 2009 Share Posted February 17, 2009 EDIT: Thinking about it, are Magic Quotes turned on, on your server? If so then the character is actualy \" which would explain why it does not trim it. I would either turn off Magic Quotes or try doing a stripslashes on the data before trimming. This is assuming you are getting the value from a POST/GET scenario. Never turn on Magic Quotes its being removed for newer versions of PHP thus you should get use to not using it Quote Link to comment https://forums.phpfreaks.com/topic/145594-php-string-trimming/#findComment-764373 Share on other sites More sharing options...
premiso Posted February 17, 2009 Share Posted February 17, 2009 Never turn on Magic Quotes its being removed for newer versions of PHP thus you should get use to not using it Did I once tell him to turn it on? I simply asked him to check if it is "on". I would either turn off Magic Quotes or try doing a stripslashes() Quote Link to comment https://forums.phpfreaks.com/topic/145594-php-string-trimming/#findComment-764375 Share on other sites More sharing options...
qmqmqm Posted February 17, 2009 Author Share Posted February 17, 2009 interesting... I discovered that since I am reading this line from a file, it actually has something weird to do with the end of line. trim($split_line[1], "\""); did not work for me; however trim(trim($split_line[1]), "\""); worked! I guess the inner trim() got rid of some weird stuff having to do with lines read from a file??? Quote Link to comment https://forums.phpfreaks.com/topic/145594-php-string-trimming/#findComment-764403 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.