GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP Help? Gurus, hook a brother up... (https://gfy.com/showthread.php?t=881560)

RayVega 01-14-2009 04:54 PM

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?

drocd 01-14-2009 05:09 PM

PHP Code:

$str '$agentid=1010303&listingid';
if(
preg_match_all('/agentid\=(\d+)&listingid/',$str,$matches)){
    
$num $matches[1][0];



RayVega 01-14-2009 05:20 PM

Quote:

Originally Posted by drocd (Post 15330373)
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!

nation-x 01-14-2009 06:41 PM

holy crap! I think this is the first time I have seen a regex posted on gfy... lol

mrkris 01-14-2009 07:07 PM

Quote:

Originally Posted by nation-x (Post 15330674)
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 


GrouchyAdmin 01-14-2009 10:18 PM

Quote:

Originally Posted by mrkris (Post 15330756)
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";

Bird 01-14-2009 10:25 PM

Whats wrong with
$num = $a['agentid']

rowan 01-14-2009 10:39 PM

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)

GrouchyAdmin 01-14-2009 11:09 PM

Quote:

Originally Posted by rowan (Post 15331356)
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

rowan 01-14-2009 11:21 PM

Quote:

Originally Posted by GrouchyAdmin (Post 15331453)
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.)

V_RocKs 01-14-2009 11:35 PM

Quote:

Originally Posted by RayVega (Post 15330242)

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 (Post 15331453)
Why does everybody hate $_REQUEST?

Why does everyone hate reading the question?

borked 01-15-2009 12:27 AM

Quote:

Originally Posted by RayVega (Post 15330421)
Thanks bro...right on target. problem solved!

although, cos I know what you're doing :winkwink: 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.";

:2 cents: <- my invoice for this wonderful piece of insight

GrouchyAdmin 01-15-2009 02:26 AM

Quote:

Originally Posted by V_RocKs (Post 15331588)
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.

tranza 01-15-2009 06:15 AM

This site maybe can help you:
www.pixel2life.com


All times are GMT -7. The time now is 08:38 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123