View Full Version : preg_split / preg_match Test for URI query substring?

06-08-2007, 05:02 PM
Hey All,

While I've muddled my way through a few regexp endeavors, for the most part they just leave me scratching my head.

I'm trying to test for the string 'list_edit=true' from a uri such as the following:

in order to get to something like


With the following, I'm able to dirive the queryString

$domain = $_SERVER['HTTP_HOST'];
$path = $_SERVER['SCRIPT_NAME'];
$queryString = $_SERVER['QUERY_STRING'];
//echo "The query sting is: " . $queryString . "<br />";
$chars = preg_split('/&/', $queryString, -1, PREG_SPLIT_OFFSET_CAPTURE);

$pattern = '/^list_edit=true/';
preg_match($pattern, substr($chars,5), $matches, PREG_OFFSET_CAPTURE);

But $matches returns an empty array.
1 - assuming this is a reasonalbe approach... what am I missing???
2 - maybe there is a better way to go about it?

06-08-2007, 05:38 PM
$domain = $_SERVER['HTTP_HOST'];
$path = $_SERVER['SCRIPT_NAME'];
$queryString = $_SERVER['QUERY_STRING'];
echo "The query sting is: " . $queryString . "<br />";
$findme = 'list_edit=true';
$pos = strpos($queryString, $findme);

if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "<script>alert('hooray');</script>";

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum