Jump to content

extracting part of specified URL


tobykw13

Recommended Posts

I am relatively new to PHP and am having some trouble. I have seen some tutorials on how to retrieve a section of the current URL with php, but what I am trying to do is a little different. I need to be able to specify any myspace URL in a form and have the output be a section of that URL. For example:

 

I input the following URL into a form field:

http://www.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=257367900

 

when the submit button is pressed the output should show:

257367900

 

I need it to be so that I can input any myspace url as such and the output will be everything after the "&friendid="

 

an example of something similar to what I am going for can be found here: http://www.bbzspace.com/overlay/link.php

 

Not sure if this is very elementary or sounds stupid but as I said I am a novice at this so any help would be appreciated! Thanks!

Link to comment
Share on other sites

You could do it with regular expressions, exploding (or technically strpos too, but I'm gonna avoid that one):

 

Regexp:

 

$url = 'http://www.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=257367900';

if(preg_match('/&friendid=([0-9]+)/', $url, $matches)) {
     print_r($matches);
     //matches[1] would be the friend id
}

 

Bleh I'm tired so I'm skipping the explode way ;p lol.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.