...

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



fuzzy1
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:

http://localhost/crm/index.php?action=EditView&module=Contacts&record=57232101-01e7-c5ad-2cd3-44fe6b82c772&offset=1&stamp=1181303566091630100&list_edit=true
in order to get to something like

if(list_edit=true){
echo"<script>alert('hooray');</script>";
}

With the following, I'm able to dirive the queryString
'action=EditView&module=Contacts&record=57232101-01e7-c5ad-2cd3-44fe6b82c772&offset=1&stamp=1181303566091630100&list_edit=true'

$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);
//print_r($chars);

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

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?

fuzzy1
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