Replacing integers

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Replacing integers

Post by anjanesh »

$SortBy is an integer

Code: Select all

$Parameters = $_SERVER['QUERY_STRING'];
if (preg_match("/SortBy=([0-9]+)(&|$)/i", $Parameters, $matches) > 0)
 {
        $Parameters = str_replace($matches[0], "SortBy=".$SortBy.$matches[2], $Parameters);
 }
If I replace line 4 with

Code: Select all

$Parameters = str_replace($matches[1], $SortBy, $Parameters);
then $Parameters is setting some other value for SortBy

Is this because $SortBy is an integer ? The first one is treated as a string because its concatenated with dot(.)s.

Thanks
Post Reply