Results 1 to 7 of 7

Thread: preg_match problems...

  1. #1
    Join Date
    Apr 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default preg_match problems...

    PHP Code:
    <?php
    $sess 
    file_get_contents("http://www.test.com/")

    if(
    preg_match("/Test/i"$sess)){
     echo 
    "Found.";
    } else {
     echo 
    "Not found.";
    }
    ?>
    Is it because I can't file_get_contents from outside websites or something? Or is there something else wrong...

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Is it because I can't file_get_contents from outside websites or something?
    I'd say it is...
    An error would be outputted if it was. Is there a php error?
    - Mike

  3. #3
    Join Date
    Apr 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No. That's why I'm skeptical. It simply says "Not found" no matter what.

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    PHP Code:
    <?php
    $sess 
    file_get_contents("http://www.test.com/")

    if(
    preg_match("/Test/i"$sess)){
     echo 
    "Found.";
    } else {
     echo 
    "Not found.";
    }
    ?>
    is looking for "Test" case-insensitive inside the actual contents of the url, not the url itself. A good way to find out what the string that is being passed I suggest that you print it out after, which is a good debugging tool.

    PHP Code:
    echo $sess 

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    No. That's why I'm skeptical. It simply says "Not found" no matter what.
    There's no error, it's just that test wasn't found.
    You may want to try a global regex though:
    Code:
    /Test/gi
    - Mike

  6. #6
    Join Date
    Apr 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well "test" wasn't what I used, what I used WAS found in the contents.

    And, I tried that in a link...it linked to the page the PHP was located on.

  7. #7
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by SessTehKing View Post
    Well "test" wasn't what I used, what I used WAS found in the contents.
    but did you print out the contents to of where-ever you sent it to, because for some reason its not finding it.

    Code:
    <?php
    $sess = file_get_contents("http://www.test.com/")
    
    echo $sess;
    
    if(preg_match("/Test/i", $sess)){
     echo "Found.";
    } else {
     echo "Not found.";
    }
    ?>
    do that to find out what is actually being passed then you will know where the problem resides

Bookmarks

Posting Permissions

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