Web Hosting Talk







View Full Version : regular expression - need help making one


JWB
01-29-2004, 05:30 PM
If I'm searching for a variable in a url such as t=VALUE then it also returns things like postcount=VALUE

Example:

Scheme:http
Domain:domain.com
path and file:/forums/showpost.php
Query:p=61867&postcount=5

we found this url is pointing at threadid: "5" (oh no)

$expression = "($crawlurl[threadvar]=[a-zA-Z0-9]&?)";
preg_match($expression,$urltoadd->get_query(),$urltoaddthreadid);

Can anyone think of a way to fix this?

Thanks

Burhan
01-31-2004, 07:18 AM
Try making your expression "un-greedy".

(.*?)

chrisS
01-31-2004, 03:18 PM
$what=explode("postcount=", $query);
print "$what[1]";

easiest way lol

chrisS
01-31-2004, 03:20 PM
wait, why not just use $_GET['postcount'] ?

CyberAlien
01-31-2004, 04:15 PM
Originally posted by chrisS
wait, why not just use $_GET['postcount'] ?
yep. or use parse_str() if you need to parse it yourself

Burhan
02-01-2004, 06:51 AM
I think he only need the t not the entire postcount part. I think lol.

OverlordQ
02-02-2004, 06:20 AM
*shudders* PHP really bastardizes regex's lol :)