w3coded php compare Stack Overflow for Teams w3coded php compare Where developers & technologists w3coded php compare share private knowledge with coworkers w3coded php compare ,I'm trying w3coded php compare to compare two urls using PHP, ensuring that the w3coded php compare domain name is the same. It cannot be the w3coded php compare sub-domain. It has to literally be the same w3coded php compare domain. Example:,Thanks for contributing an w3coded php compare answer to Stack Overflow!, w3coded php compare w3coded php compare Meta Stack w3coded php compare Overflow
Use parse_url()
$url1 = parse_url("http://www.google.co.uk");
$url2 = parse_url("http://www.google.co.uk/pages.html");
if ($url1['host'] == $url2['host']){
//matches
}
simple, use parse_url()
$url1 = parse_url('http://www.google.co.uk');
$url2 = parse_url('http://www.google.co.uk/pages.html');
if($url1['host'] == $url2['host']){
// same domain
}
You could use parse_url for this
$url1 = parse_url('http://www.google.com/page1.html');
$domain1 = $url1['host'];
$url2 = parse_url('http://www.google.com/page2.html');
$domain2 = $url2['host'];
if($domain1 == $domain2){
// something
}
Expanding the answer given by Ariel, the code you could use is similar to the following one:
<?php
compare_host('http://www.google.co.uk', 'http://www.something.co.uk/pages.html');
function compare_host($url1, $url2)
{
// PHP prior of 5.3.3 emits a warning if the URL parsing failed.
$info = @parse_url($url1);
if (empty($info)) {
return FALSE;
}
$host1 = $info['host'];
$info = @parse_url($url2);
if (empty($info)) {
return FALSE;
}
return (strtolower($host1) === strtolower($info['host']));
}
Last Update : 2023-09-22 UTC 12:14:40 PM
Last Update : 2023-09-22 UTC 12:14:21 PM
Last Update : 2023-09-22 UTC 12:14:02 PM
Last Update : 2023-09-22 UTC 12:13:51 PM
Last Update : 2023-09-22 UTC 12:13:41 PM
Last Update : 2023-09-22 UTC 12:13:09 PM
Last Update : 2023-09-22 UTC 12:12:49 PM