![]() |
![]() |
![]() |
||||
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. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Jul 2004
Location: New York ICQ#348007554
Posts: 4,212
|
![]() 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? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Aug 2007
Posts: 128
|
PHP Code:
__________________
230-699 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Jul 2004
Location: New York ICQ#348007554
Posts: 4,212
|
Thanks bro...right on target. problem solved!
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
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
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
Confirmed User
Join Date: May 2005
Posts: 2,737
|
Quote:
PHP Code:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
Quote:
Here, have a link scraper. Code:
$preg = "/a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>/i";
__________________
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Jan 2005
Location: Stockton
Posts: 4,365
|
Whats wrong with
$num = $a['agentid']
__________________
ICQ:268731675 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
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)
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
Quote:
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
__________________
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Too lazy to set a custom title
Join Date: Mar 2002
Location: Australia
Posts: 17,393
|
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.) |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Damn Right I Kiss Ass!
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,405
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Totally Borked
Industry Role:
Join Date: Feb 2005
Posts: 6,284
|
although, cos I know what you're doing
![]() if(preg_match('/agentid\=(\d{10})&listingid/',$str,$matches)){ cos otherwise, the regexp given would pick up also: $a="...$agentid=1&listingid...etc."; ![]()
__________________
![]() 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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
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.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
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. |
![]() |
![]() ![]() ![]() ![]() ![]() |