How do you check if a given URL matches at least a sitename?
I have:
$url_to_match = 'http://sub.somesite.com/';
I want to say "MATCH found" for input starting with http://sub.somesite.com only.
Any help would be very much appreciated.
Use PHP's parse_url():
$url = 'http://sub.somesite.com/';
if ('sub.somesite.com' === parse_url($url, PHP_URL_HOST)) {
// we have a match
}
use parse_url
example:
function match_url($base,$input)
{
$base_host = parse_url($base,PHP_URL_HOST);
$input_host = parse_url($input,PHP_URL_HOST);
if( $base_host === $input_host ) {
return true;
}
else
{
return false;
}
}
$base_url = 'http://sub.somesite.com';
$input_url = 'http://sub.somesite.com//bla/bla';
echo (match_url($base_url,$input_url)) ? "URL matched" : "URL mismatched";
I think you need to tell us what you are doing since this request makes no design sense.
However, to answer the question.
if(strpos($url_to_match, 'http://sub.anothersite.com/bla') !== FALSE) print 'bad string';
$haystack. XD