...

View Full Version : how to perform this ??



PHPycho
07-06-2007, 01:43 PM
Hello forums !!
Consider the following case:

$ref_url = "http://www.xyz.com";
// or $ref_url = "http://xyz.com" (without 'www')
$check_url = "http://xyz.com/index.php?action=a&mode=b&blabla";
I want to check the if the $check_url contains the $ref_url or not.
Thanks in advance to all of you.

mlse
07-06-2007, 01:51 PM
Methinks the following should work:



$ref_url = "http://www.xyz.com";
// or $ref_url = "http://xyz.com" (without 'www')
$check_url = "http://xyz.com/index.php?action=a&mode=b&blabla";

$ref_parts = parse_url($ref_url);
$check_parts = parse_url($check_url);

var_dump(str_replace("www.", "", $ref_parts["host"]) === str_replace("www.", "", $check_parts["host"]));


You could always make it stronger by only removing the www. if it is at the front of the host element of the url parts, check for NULL host element, etc. I've included the str_replace on the RHS of the === for completeness.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum