Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 01-14-2009, 04:54 PM   #1
RayVega
Confirmed User
 
RayVega's Avatar
 
Industry Role:
Join Date: Jul 2004
Location: New York ICQ#348007554
Posts: 4,212
PHP Help? Gurus, hook a brother up...

Been a while since I wrote code and I'm working on a small script and sadly I'm stuck on what should be a relatively easy regular expression match in PHP.

I have a variable with a bunch of text and need to match the text between two different patterns and assign it to a variable.

Ex.
$a="...$agentid=1010303&listingid...etc.";

I need to grab text between $agentid= and &listingid and assign to variable so I am left with $num="1010303". Now, I have to do some things with that number but first need to extract it from the variable.

Rather than sift through web pages and using trial and error, I figure one of you guys can spew it out off the top of your head.

Any ideas?
__________________
Ray "The Don" Vega

Managing Director
Private Equity Fund

[email protected]
RayVega is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 05:09 PM   #2
drocd
Confirmed User
 
Join Date: Aug 2007
Posts: 128
PHP Code:
$str '$agentid=1010303&listingid';
if(
preg_match_all('/agentid\=(\d+)&listingid/',$str,$matches)){
    
$num $matches[1][0];

__________________
230-699
drocd is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 05:20 PM   #3
RayVega
Confirmed User
 
RayVega's Avatar
 
Industry Role:
Join Date: Jul 2004
Location: New York ICQ#348007554
Posts: 4,212
Quote:
Originally Posted by drocd View Post
PHP Code:
$str '$agentid=1010303&listingid';
if(
preg_match_all('/agentid\=(\d+)&listingid/',$str,$matches)){
    
$num $matches[1][0];

Thanks bro...right on target. problem solved!
__________________
Ray "The Don" Vega

Managing Director
Private Equity Fund

[email protected]
RayVega is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 06:41 PM   #4
nation-x
Confirmed User
 
nation-x's Avatar
 
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
holy crap! I think this is the first time I have seen a regex posted on gfy... lol
nation-x is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 07:07 PM   #5
mrkris
Confirmed User
 
Join Date: May 2005
Posts: 2,737
Quote:
Originally Posted by nation-x View Post
holy crap! I think this is the first time I have seen a regex posted on gfy... lol
Really? Let me add another. drocd should remember this regex I pasted him a while ago.

PHP Code:
@ox.+ref "(.+)".+c="(.+)".+e="(.+)".+ft">(.+)<@Us 
__________________

PHP-MySQL-Rails | ICQ: 342500546
mrkris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 10:18 PM   #6
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by mrkris View Post
Really? Let me add another. drocd should remember this regex I pasted him a while ago.

PHP Code:
@ox.+ref "(.+)".+c="(.+)".+e="(.+)".+ft">(.+)<@Us 
Rails is for snails.

Here, have a link scraper.

Code:
$preg = "/a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>/i";
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 10:25 PM   #7
Bird
Confirmed User
 
Bird's Avatar
 
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
Whats wrong with
$num = $a['agentid']
__________________
ICQ:268731675
Bird is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 10:39 PM   #8
rowan
Too lazy to set a custom title
 
Join Date: Mar 2002
Location: Australia
Posts: 17,393
As Bird suggested, if those variables are actually part of the URL that is running the script then it's easy peasy... $num = $_GET["agentid"]; (replace GET with POST if it's a form)
rowan is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 11:09 PM   #9
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by rowan View Post
As Bird suggested, if those variables are actually part of the URL that is running the script then it's easy peasy... $num = $_GET["agentid"]; (replace GET with POST if it's a form)
Why does everybody hate $_REQUEST?

I was praying that's what Bird meant, and not eval() parse_str($_SERVER["QUERY_STRING"]). You can only imagine what kind of shit I've seen to even assume such a crazy thing
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 11:21 PM   #10
rowan
Too lazy to set a custom title
 
Join Date: Mar 2002
Location: Australia
Posts: 17,393
Quote:
Originally Posted by GrouchyAdmin View Post
Why does everybody hate $_REQUEST?
Just habit from writing scripts that are to be used by several people. Keep it more specific.

Some webmasters will do odd things, like a javascript call that redirects to your site by POSTing to it. (The reason for this? It blocks/clears the referer.)
rowan is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2009, 11:35 PM   #11
V_RocKs
Damn Right I Kiss Ass!
 
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,405
Quote:
Originally Posted by RayVega View Post

I have a variable with a bunch of text and need to match the text between two different patterns and assign it to a variable.
Quote:
Originally Posted by GrouchyAdmin View Post
Why does everybody hate $_REQUEST?
Why does everyone hate reading the question?
V_RocKs is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2009, 12:27 AM   #12
borked
Totally Borked
 
borked's Avatar
 
Industry Role:
Join Date: Feb 2005
Posts: 6,284
Quote:
Originally Posted by RayVega View Post
Thanks bro...right on target. problem solved!
although, cos I know what you're doing the agent id is a 10 digit string and will only occur once, so to be absolutely sure....

if(preg_match('/agentid\=(\d{10})&listingid/',$str,$matches)){

cos otherwise, the regexp given would pick up also:

$a="...$agentid=1&listingid...etc.";

<- my invoice for this wonderful piece of insight
__________________

For coding work - hit me up on andy // borkedcoder // com
(consider figuring out the email as test #1)



All models are wrong, but some are useful. George E.P. Box. p202

Last edited by borked; 01-15-2009 at 12:30 AM..
borked is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2009, 02:26 AM   #13
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by V_RocKs View Post
Why does everyone hate reading the question?
You've done two things wrong for the adult industry:

1) Assuming he has the variable defined locally.
2) Assuming he knows what a variable is.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2009, 06:15 AM   #14
tranza
ICQ: 197-556-237
 
Join Date: Jun 2003
Location: BRASIL !!!
Posts: 57,559
This site maybe can help you:
www.pixel2life.com
__________________
I'm just a newbie.
tranza is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.