SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: How To =>

  1. #1
    SitePoint Addict sleepingdanny's Avatar
    Join Date
    Oct 2002
    Location
    Israel
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How To =>

    Is there a way to fopen a page in a certein web site and to look for a certein word in or a sentence in that page??

    Bellow is a code that I hopped will work, but it didn't... Can you help me?


    PHP Code:
    <?
    $fp
    =fopen("Site","r" );
    if(
    eregi("TEXT HERE",$fp)){
    print 
    "<b>TEXT</b>";
    }
    else{
    print 
    "<b>TEXT</b>";
    }
    fclose($fp);
    ?>
    Last edited by sleepingdanny; May 1, 2003 at 06:06.

  2. #2
    SitePoint Member
    Join Date
    Apr 2003
    Location
    the Netherlands
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fopen() returns a file pointer, not the contents of the file. $fp is just a number identifying the file, that you can use with other file functions. Before you use eregi to check the contents of the file, you'll first have to get that contents. You can use fread() to do that:
    PHP Code:
    <?
    // open file
    $fp=fopen("Site","r");
    // read file from file pointer
    $contents '';
    while (
    $buffer fread($fp4096)) {
        
    $contents .= $buffer;
    }
    // close file
    fclose($fp);

    // $contents contains the contents of the file
    if(eregi("TEXT HERE",$contents)){
    print 
    "<b>TEXT</b>";
    }
    else{
    print 
    "<b>TEXT</b>";
    }
    ?>
    There's an explanation of the fread() function on the PHP website.

  3. #3
    SitePoint Addict sleepingdanny's Avatar
    Join Date
    Oct 2002
    Location
    Israel
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its not working - THANKS anyway, Can anyone else try??

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Check the manual at www.php.net for the file command ....
    PHP Code:
    <?php
    // Get a file into an array.  In this example we'll go through HTTP to get 
    // the HTML source of a URL.
    $lines file ('http://www.example.com/');

    // Loop through our array, show html source as html source; and line numbers too.
    foreach ($lines as $line_num => $line) {
        echo 
    "Line #<b>{$line_num}</b> : " htmlspecialchars($line) . "<br>\n";
    }

    // Another example, let's get a web page into a string.  See also file_get_contents().
    $html implode (''file ('http://www.example.com/'));
    ?>
    Ian Anderson
    www.siteguru.co.uk


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
  •