If I have the string "somepage/otherpage/" set to $newUrl, how do I get "otherpage" set to $secondPage? Here is what I have.
$newUrl = $_GET['newUrl'];
preg_match("/^[A-Za-z0-9' -_ ]*(?=\/)/", $newUrl, $matches);
$firstPage = $matches[0];
echo $firstPage, "<br>";
preg_match("/(?<=\/)[A-Za-z0-9().&-', -_ ]*(?=\/)/", $newUrl, $matches);
$secondPage = $matches[0];
echo $secondPage, "<br><br>";
$firstPage is working, $secondPage isn't.
I need it to work with "somepage/otherpage/" and "somepage/otherpage"
$newUrl = $_GET['newUrl'];
preg_match("/^[A-Za-z0-9' -_ ]*(?=\/)/", $newUrl, $matches);
$firstPage = $matches[0];
echo $firstPage, "<br>";
preg_match("/(?<=\/)[A-Za-z0-9().&-', -_ ]*(?=\/)/", $newUrl, $matches);
$secondPage = $matches[0];
echo $secondPage, "<br><br>";
$firstPage is working, $secondPage isn't.
I need it to work with "somepage/otherpage/" and "somepage/otherpage"
Last edited: