Jump to content

php string trimming


qmqmqm

Recommended Posts

<?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.

 

Link to comment
https://forums.phpfreaks.com/topic/145594-php-string-trimming/#findComment-764369
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/145594-php-string-trimming/#findComment-764373
Share on other sites

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()
Link to comment
https://forums.phpfreaks.com/topic/145594-php-string-trimming/#findComment-764375
Share on other sites

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???

Link to comment
https://forums.phpfreaks.com/topic/145594-php-string-trimming/#findComment-764403
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.