Whois script need help, how to detect "www"?

Discussion in 'PHP' started by owntype, Jul 6, 2008.

  1. #1
    Hi, I am modifying a whois script.

    I am currently using the following code to detect the www.xxx.com format and transfer it into xxx.com

    if(isset($_GET['query'])){
    $query = str_replace("www.","",$_GET['query']);

    But if I am checking a domain e.g. xxxwww.com, it will also be replaced and changed to xxx.com

    How to solve this problem? I am not into coding, so please if anyone can help me to find a simple solution.

    Thanks :)
     
    owntype, Jul 6, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    if(isset($_GET['query'])){
    $query = preg_replace('/www./','',$_GET['query']);
     
    php-lover, Jul 6, 2008 IP
  3. owntype

    owntype Well-Known Member

    Messages:
    1,169
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Thanks, php-lover, but it doesnt work, as if the actual domain is aboutwww.com, it will replace the domain to aboutcom which causes error.
     
    owntype, Jul 6, 2008 IP
  4. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #4
    okay then take off the dot.

    try this one.

    if(isset($_GET['query'])){
    $query = preg_replace('/www/','',$_GET['query']);
     
    php-lover, Jul 6, 2008 IP
  5. zerofill

    zerofill Member

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #5
    Do something like this man...

    <?php
    if(isset($_GET['query']) && substr($_GET['query'], 0, 4) == 'www.') {
    $query = substr($_GET['query'], 4);
    }
    echo $query;
    ?>
     
    zerofill, Jul 6, 2008 IP
    owntype likes this.
  6. owntype

    owntype Well-Known Member

    Messages:
    1,169
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #6
    zerofill, Thanks a lot!!!
     
    owntype, Jul 7, 2008 IP
  7. zerofill

    zerofill Member

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #7
    np..glad to help 8)
     
    zerofill, Jul 7, 2008 IP