strings

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

strings

Post by lexx »

Say I have a string $string="hello==" how do I remove the last two character from the string?
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

Code: Select all

$string = substr($string,0,(strlen($string)-2));
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

Post by lexx »

how about remove specific character like "=" from the string?
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

Code: Select all

$string = ereg_replace("=","",$string);
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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 "=".
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: strings

Post 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
Post Reply