Jump to content

retrieving information from url..


php_begins

Recommended Posts

i have had a difficult time trying to work this out.I need to do some pattern matching for certain urls and retrieve information from it.

For example,

$url=http://www.test.com/showpic.php?do=showpic&u=89165&a=34933

 

if $url contains the value showpic.php,then i need to retrieve the following

{

  $u=value of u(i.e. 89165 in this case)

  $a=value of a(i.e. 34933 in this case)

}

else do nothin..

 

the format of the url will always be the same as above if it contains showpic.php

Link to comment
https://forums.phpfreaks.com/topic/251989-retrieving-information-from-url/
Share on other sites

Here's just something simple I did using preg_match to see if showpic.php exists in the url, and if does find the u and a values.

 

<?php
$url = "http://www.test.com/showpic.php?do=showpic&u=89165&a=34933";

if (preg_match("/showpic.php/i",$url)) {
echo "yes <br />";
parse_str($url, $values);
$a_value = $values['a'];
$u_value = $values['u'];

echo "a is $a_value <br />";
echo "u is $u_value <br />";

} else {
echo "not showpic.php";
}
?>

 

result is:

yes

a is 34933

u is 89165

 

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.