Jump to content

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

 

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.