Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    217
    Thanks
    1
    Thanked 0 Times in 0 Posts

    how to perform this ??

    Hello forums !!
    Consider the following case:
    PHP Code:
    $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.

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    Methinks the following should work:

    PHP Code:
    $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.
    Last edited by mlse; 07-06-2007 at 12:53 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •