Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.