Reputation: 23
I want to run this PHP function --
$querystring_arr='maxResults=50&startIndex=50&sort=date';
$str=preg_replace("(&startIndex=)?[0-9]*(&)?","&startIndex=".$sindex."&",$querystring_arr);
When I print $str
it gives the error:
Warning: preg_replace() [function.preg-replace]: Unknown modifier '\' in C:\xampp\htdocs\myapp\paginator.class.php on line 112
Please, where is my regular expression wrong?
Upvotes: 1
Views: 143
Reputation: 490657
You need to wrap you regex with delimiters.
preg_replace("/(&startIndex=)?\d*&?/","&startIndex=".$sindex."&",$arr);
Alternatively, don't use a regex and use what PHP provides.
parse_str($str, $params);
if (get_magic_quotes_gpc()) {
$params = array_map('stripslashes', $params);
}
$params["startIndex"] = $sindex;
$str = http_build_query($params);
Upvotes: 2