Forum Moderators: coopster

Message Too Old, No Replies

quick regular expression help

         

webdev81

2:59 pm on Aug 22, 2007 (gmt 0)

10+ Year Member



Hi,

I'm trying to pick a value from a url.

url example 1
http://www.example.com/index.php?id=2123123

example 2
http://www.example.com/index.php?id=2123123&a=asdad

regular expression
preg_match("/id=(.*?)&¦\Z/",trim($url),$match);

this regular expression seems to work for the 2nd url but not for the first. if i replace the ¦ sign with? or just take the & sign out all togather then it works for the first URL.

Any help guys?

Thanks

[edited by: dreamcatcher at 3:09 pm (utc) on Aug. 22, 2007]
[edit reason] Use example.com, thanks. [/edit]

d40sithui

6:10 pm on Aug 22, 2007 (gmt 0)

10+ Year Member



if you simply want to ge the value of id or a, you can get them by
<?
$id = $_REQUEST['id'];
$a = $_REQUEST['a'];
?>

webdev81

8:54 am on Aug 23, 2007 (gmt 0)

10+ Year Member



They are not a querystrings. The urls are stored in a DB.

Cheers!

vincevincevince

9:27 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$url_components=parse_url($url);
parse_str($url_components[query],$arguments);
$id=$arguments[id];

webdev81

9:47 am on Aug 23, 2007 (gmt 0)

10+ Year Member



it worked! :D

thanks a lot pal

vincevincevince

9:50 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The moral of the story... don't reinvent the wheel ;)