- strpos: documentation ( source)
- parse_url: documentation ( source)
<?php
function get_converted_url($full_url)
{
$urls_to_convert = ['/some/url/', '/other/url'];
$parsed_url = parse_url($full_url);
$path = $parsed_url['path'];
foreach ($urls_to_convert as $url_to_convert) {
if (strpos($path, $url_to_convert, 0) !== false) {
return $url_to_convert;
}
}
return $path;
}
echo get_converted_url('/test/some/url/') . "\n";
echo get_converted_url('/some/url/a/b/') . "\n";
echo get_converted_url('/other/url/a/b/') . "\n";
echo get_converted_url('/strange/url/a/b/') . "\n";