Guidance in changing a variable

I need some guidance in what command to use to change the following variable to just have the numbers in bearing in mind that the name, number and user will change everytime.

$vid = “http://website.com/asdasd/user/1232131/name

Any help would be fantastic

Are you looking for something like this:

$vid = “http://website.com/asdasd/".$user."/".$number."/”.$name;

No, people will input urls e.g. http://website.com/asdasd/user/1232131/name
And the bit that changes is the user, number and name. I want it to get rid of everything apart from the number, as that is the crucial bit.

You will need to have the URL in a variable which it looks as though you have already.

Then I would look into using some str_replace(), substr(), strpos() functions to strip out all the content you don’t need.

There are ereg fucntions that are more powerful, but can be a little more difficult to understand.

If you need to look up those function look at http://www.php.net

HTH!

I have looked at the commands on php.net but cant seem to be able to use it for me. As there are parts which change.

Any more help would be great

I’d advise the use of split() or explode() actually, and using / as a delimiter.

Yes I would have to agree with Zyppora on this.

@CTBC - Sorry for the misguidance, I didn’t clearly think out the problem and gave an invalid solution!

My apologies again!

Ragster, you didn’t give an invalid solution, just a ‘scenic-route’ solution :wink: explode()/split() can be achieved through strpos()/substr()/str_replace() if you’re a masochist :stuck_out_tongue:

Cheers everyone this worked perfectly

Sponsor our Newsletter | Privacy Policy | Terms of Service