开发者

Using PHP to extract part of a url

If you have a url like this: rapidshare.com/#!download|value1|values|value3

and yo开发者_Go百科u know the numbers how can you extract the value 1 and the value 3

Is there a way to extract the values between the 2nd and 3rd | and 3rd and 4th |

Thanks!


$array = explode('|', $url);

And use $array[$index];


$url =  'http://rapidshare.com/#!download|546l3|448704915|eu.heinelt.ifile_1.4.1-2_iphoneos-arm_fabius.deb|2915';
$urlparts = explode("|",$url);

will give you all the parts as array in $urlparts


Al of the above are 1 way of doing this, but if your script is always extracting data after your script name. as in: somepage.com/download.php?var1='val1'&var2='val2' the only relevant part for you is var1='val1'&var2='val2'

Luckily, PHP has a superglobal that can help. $_SERVER['QUERY_STRING'] . This way you can get an array of values, much cleaner and not have to worry that your explode seperator was being used on any other part of the URL.

$url = $_SERVER['REQUEST_URI'];
$values = explode("|", $url);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜