views:

70

answers:

4

Hi guys,

In PHP the trim function has a parameter for trimming specific characters (handy for leading zeros and the like). I can't seem to get it to accept a vertical bar (|) character. Anyone know how to get this working? I tried the hex value but had no luck. I'm sure it's something simple.

Cheers

+3  A: 

It works for me:

var_dump(trim('|foo|', '|')); // string 'foo' (length=3)

Maybe you have some whitespace around it, or your're using the wrong pipe character? ¦ vs |

Greg
I thought you might have been on to something with the wrong pipe char, but trying this:echo trim(substr($response, strpos($response,'AF')+2),'#¦|');still results in this: You do not have any fee needed to pay.|
Cory Dee
I copied
Greg
The var_dump gave: string(41) "#You do not have any fee needed to pay.| ", so I added in a white space character with no luck:echo trim(substr($response, strpos($response,'AF')+2),'#¦|\ ');
Cory Dee
Hrrrm still working OK for me
Greg
A: 

Works for me:

$str = "|test string";
echo trim($str, "|");

test string

Can you show some of your code?

Maybe you want to remove a | in the middle of a string you can use str_replace

str_replace("|", "", $str);
jjclarkson
A: 
echo trim('|text|', '|'); // returns text

The second param was added in PHP 4.1!

powtac
A: 

trim() only removes characters from the beginning and end of a string. If you'd like to replace characters in the middle of a string, use str_replace(), or preg_replace() if you like regular expressions.

gnud