string manipulation help

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
jake2891
Forum Newbie
Posts: 2
Joined: Fri Jun 13, 2008 4:32 am

string manipulation help

Post by jake2891 »

Hi guys,

Im trying to search a string for the last forwardslash and remove everything after and including the forward slash.

for example my string '/ggfx/modify/89/97/bee.jpeg/121498954583267'

i want to be left with /ggfx/modify/89/97/bee.jpeg

any help will be greatly appreciated.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: string manipulation help

Post by Bill H »

see strrpos() and substr()
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: string manipulation help

Post by jaoudestudios »

Step1
use strrpos to find the position of the character within your string.

Step 2
use substr to chop the bit you want out
Last edited by jaoudestudios on Wed Jul 02, 2008 7:49 am, edited 1 time in total.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: string manipulation help

Post by jaoudestudios »

ah Bill beat me to it :D
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: string manipulation help

Post by highjo »

you can use strripos too
look here http://www.php.net/manual/en/function.strripos.php
Post Reply