PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
sulen
Forum Commoner
Posts: 79 Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:
Post
by sulen » Tue Apr 12, 2005 7:19 pm
I have a variable degreetypeid which holds a URL like
$degreetypeid="start3.php?degreetypeid=1°reetype=Associates"
I need to parse this URL to get the value of degreetypeid in the URL which in the above case is 1. The code I have used is as under
Code: Select all
<? preg_match("/[degreetypeid]\s*=\s*(.*?)/i", $degreetypeid, $matches);
$degree = $matches[1];
echo $degree;
?>
But it doesnt seem to work for some reason. Can anyone tell me what the mistake is. Thanks
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Apr 12, 2005 7:31 pm
sulen wrote: I have a variable degreetypeid which holds a URL like
$degreetypeid="start3.php?degreetypeid=1°reetype=Associates"
I need to parse this URL to get the value of degreetypeid in the URL which in the above case is 1. The code I have used is as under
Code: Select all
<? preg_match("/[degreetypeid]\s*=\s*(.*?)/i", $degreetypeid, $matches);
$degree = $matches[1];
echo $degree;
?>
But it doesnt seem to work for some reason. Can anyone tell me what the mistake is. Thanks
[abc] means match any SINGLE character 'a', 'b', or 'c' so your [degreetypeid] is only a single char
do this
(Ignore my escaping \= I always do it for some reason).
Code: Select all
preg_match("/\?degreetypeid\s*\=\s*([^\&]*)/i", $degreetypeid, $matches);
echo $matches[1];
If it needs to be more specific then ask me
sulen
Forum Commoner
Posts: 79 Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:
Post
by sulen » Tue Apr 12, 2005 8:22 pm
Yeah. That works thank you very much for the quick repsonse. Thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Apr 14, 2005 5:57 pm