Skip to content

Instantly share code, notes, and snippets.

@ricardosiri68
Created January 6, 2015 00:10
Show Gist options
  • Select an option

  • Save ricardosiri68/0391be5d236ed807a506 to your computer and use it in GitHub Desktop.

Select an option

Save ricardosiri68/0391be5d236ed807a506 to your computer and use it in GitHub Desktop.
<?php
$expresion = '/page=[0-9]+/';
$pages = [
"http://localhost/ejemplo/pagina?page=1" => "http://localhost/ejemplo/pagina?page=2",
"http://localhost/ejemplo/pagina?page=1&foo=20" => "http://localhost/ejemplo/pagina?page=2&foo=20",
"http://regex101.com/?page=1" => "http://regex101.com/?page=2",
"http://regex101.com/?page=1&foo=20" => "http://regex101.com/?page=2&foo=20"
];
$page = 2;
foreach ($pages as $test => $control) {
$result = preg_replace($expresion, "page=$page", $test);
if ($result <> $control) {
echo "<b>" . $result . "</b> - " . $control . "</br>";
} else {
echo "<b>ok</b> - $test </br>";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment