Character String Question

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
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Character String Question

Post by Stelios »

Hi everybody,

Is there any way I can echo data from a mysql database without displaying the last 4 characters of the string?

Thanks! :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql has a function called SUBSTRING() which can be used with their CHARLENGTH() functions.. there are similar functions in php as well: substr() and strlen()
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

don't even need strlen, just feed substr with a negative length, fe:

Code: Select all

$str = substr($str, 0, -4);
Post Reply