IF statement to check url in PHP with RegEx
one text
Solution:
The slashes in $spanishPage are for regular expressions, strpos doesn't use them
<?php
// a regular expression that will get a language code out of a URL
$regEx = '#/(\w\w)/(.*)$#';
// use the regex with the request URL
if(preg_match_all($regEx,'https://www.example.com/es/my-page.php',$matches)) {
if (is_dir($matches[1][0])) {
echo 'Directory is '.$matches[1][0].PHP_EOL;
echo 'Page is '.$matches[2][0];
if (!is_file($matches[2][0])) {
echo ' not found';
}
} else {
echo 'Directory '.$matches[1][0].' doesn\'t exist'.PHP_EOL;
}
}
Source