![]() |
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? |
PHP Code:
|
Quote:
|
holy crap! I think this is the first time I have seen a regex posted on gfy... lol
|
Quote:
PHP Code:
|
Quote:
Here, have a link scraper. Code:
$preg = "/a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>/i"; |
Whats wrong with
$num = $a['agentid'] |
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)
|
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 |
Quote:
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.) |
Quote:
Quote:
|
Quote:
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 |
Quote:
1) Assuming he has the variable defined locally. 2) Assuming he knows what a variable is. |
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