Page 1 of 1

strings

Posted: Fri Jun 21, 2002 9:25 pm
by lexx
Say I have a string $string="hello==" how do I remove the last two character from the string?

Posted: Fri Jun 21, 2002 9:28 pm
by will

Code: Select all

$string = substr($string,0,(strlen($string)-2));

Posted: Fri Jun 21, 2002 9:31 pm
by lexx
how about remove specific character like "=" from the string?

Posted: Fri Jun 21, 2002 9:48 pm
by will

Code: Select all

$string = ereg_replace("=","",$string);

Posted: Mon Jun 24, 2002 9:17 am
by Wayne

Code: Select all

$string = str_replace("=", "", $string);
would be more efficient on the server if you are only replacing a specific character such as "=".

Re: strings

Posted: Mon Jun 24, 2002 9:25 am
by twigletmac

Code: Select all

$string = substr($string,0,(strlen($string)-2));
This could be simplified to,

Code: Select all

$string = substr($string, 0, -2);
Mac