Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
regular expression to extract number
Old 10-23-2009, 08:40 AM regular expression to extract number
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
Hi

how do i use a regular expression to extract the number between referrer= and & in the below:

referrer=737475791&

cheers
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 10-23-2009, 08:56 AM Re: regular expression to extract number
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
:-)
Easy:

[0-9]{1,}
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 10-23-2009 at 08:57 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-23-2009, 09:00 AM Re: regular expression to extract number
numbenator's Avatar
Webmaster Talker

Posts: 516
Location: London
Trades: 0
i did it like
if (preg_match('/referrer=(.*?)&/s', $_GET[next], $regs))
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 10-23-2009, 09:42 AM Re: regular expression to extract number
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
With that wildcard, you will get everything between "referrer=" and "&".
Not just numbers.

Adapt your code to be able to handle it, if needed.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 10-23-2009 at 09:44 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-23-2009, 05:39 PM Re: regular expression to extract number
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
You can also use http_parse_params() to parse a string into an array.

http_parse_params($string, $array);

$referrer - $array['referrer'];
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-25-2009, 08:09 AM Re: regular expression to extract number
Average Talker

Posts: 18
Trades: 0
if (preg_match('/referrer=([0-9]+)&/', $_GET[next], $regs))

[0-9] means any number in that range and + means one or more

So it will work for referrer=125890& but not work for referrer=&
__________________

Please login or register to view this content. Registration is FREE
Don Giovani is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to regular expression to extract number
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.07880 seconds with 12 queries