Reputation: 4253
I have a problem in a variable in PHP that I want to remove the first and last \n from a string but not the \n in the text.
eg:
<--------------\n //I want to remove this (if exists)
some text \n
some text \n
<--------------\n //I want to remove this (if exists)
Any ideas?
Upvotes: 1
Views: 1864
Reputation: 662
Trim PHP function makes what you want to do : All whitespaces before and after string are removed.
$someText = " bulbul ";
echo trim($sometext); // "bulbul"
Upvotes: 3
Reputation: 787
trim()
strips whitespace from the beginning and end of a string. I believe this is what you need. More on the trim() function: http://php.net/manual/en/function.trim.php
Upvotes: 0