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
https://forums.phpfreaks.com/topic/71763-extracting-part-of-specified-url/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.