#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    piscataway, NJ, USA
    Posts
    4
    Rep Power
    0
    Hi,

    I have a php file trying to grab the title of a html file. It worked when referring using relative path (files in the same directory), but did not work with absolute path like http://www.homew.com/...

    I read an article saying this happened maybe the Cache issue on the server, or proxy. I am not sure what that is.

    Can somebody try it in your side see what happens?
    Here is where the file locates: http://www.homew.com/temp/readtitle.php3

    Following is the code for the file
    <?
    echo "<font color=green>This part works fine using $filename = "readtitle.htm" <br></font>";
    $filename = "readtitle.htm";
    $fd = fopen ($filename, "r");
    $contents = fread ($fd, filesize ($filename));
    if (ereg("<title>(.*)", $contents, $out)) { echo $out[1] ; }
    fclose ($fd);


    echo "<br><P><font color=red >This part DOES NOT work using $filename = "http://www.homew.com/temp/readtitle.htm" <br>,";
    echo "if you do not see anything below.<br></font>";

    $filename = "http://www.homew.com/temp/readtitle.htm";
    $fd = fopen ($filename, "r");
    $contents = fread ($fd, filesize ($filename));

    if (ereg("<title>(.*)", $contents, $out)) { echo $out[1] ; }
    fclose ($fd);
    ?>

    Any thoughts, appreciate

    Changgen

  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Try to use file() function to get the content from remote files.

    $grabbed_file=file("http://www.homew.com/temp/readtitle.htm");

    now you can do rest of the things with your '$grabbed_file'.




    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    piscataway, NJ, USA
    Posts
    4
    Rep Power
    0


    Dear Shiju,

    I tried, still did not work. Here is the Error message:.

    Warning: Unable to access Array in /www/homew/temp/readtitle.php3 on line 16

    Warning: fopen("Array","r") - No such file or directory in /www/homew/temp/readtitle.php3 on line 16

    Warning: Unable to find file identifier 0 in /www/homew/temp/readtitle.php3 on line 17

    Warning: Unable to find file identifier 0 in /www/homew/temp/readtitle.php3 on line 20

    Do you know why?

    Thanks.

    Changgen

    >>>>>
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Shiju Rajan:
    Try to use file() function to get the content from remote files.

    $grabbed_file=file("http://www.homew.com/temp/readtitle.htm");

    now you can do rest of the things with your '$grabbed_file'.


    [/quote]

  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    Warning: fopen("Array","r") - No such file or directory in /www/homew/temp/readtitle.php3 on line 16
    >>


    ohh!!
    I think you have passed that variable to fopen() function.

    now you don't have to pass the value to fopen().

    ---
    try like this:

    <?
    $grabbed_file=file("http://www.webshiju.com/index.htm");

    // all the contents have stored in this $grabbed_file.
    //now take title from that..

    if (ereg("<title>(.*)", $grabbed_file, $out)) { echo $out[1] ; }
    ?>


    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited August 22, 2000).]
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Niteroi, RJ, Brazil
    Posts
    30
    Rep Power
    15
    I think you should replace your <title>(.*) for <title>(.*)</title> so it stops grabbing when it hits </title>

    try it... may not solve the whole problem, but will help (probably)

    ------------------
    Eduardo Teixeira Cardoso
    PHP Programmer from Brazil
    idnotfound@vircio.com.br
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    51
    Rep Power
    15
    i hate delimiters, i need to get better at them.

    sam
  12. #7
  13. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Just try the following code..this will work fine...

    <?
    $grabbed_file=file("http://www.webshiju.com/index.htm");
    $count=count($grabbed_file);

    for($a=0;$a<$count;$a++){
    //loop through the file content and get the title.
    if (eregi("<title>(.*)</title>", $grabbed_file[$a], $out)){
    $title=$out[0];
    }
    }

    $title=substr($title,7,-8);
    //get the title.and remove <title> tags

    echo $title;

    ?>


    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited August 22, 2000).]
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    piscataway, NJ, USA
    Posts
    4
    Rep Power
    0
    This works fine.

    Thanks for all your help.

    Changgen


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Shiju Rajan:
    Just try the following code..this will work fine...

    <?
    $grabbed_file=file("http://www.webshiju.com/index.htm");
    $count=count($grabbed_file);

    for($a=0;$a<$count;$a++){
    //loop through the file content and get the title.
    if (eregi("<title>(.*)</title>", $grabbed_file[$a], $out)){
    $title=$out[0];
    }
    }

    $title=substr($title,7,-8);
    //get the title.and remove <title> tags

    echo $title;

    ?>

    [/quote]

Similar Threads

  1. Replies: 4
    Last Post: May 18th, 2004, 05:21 AM
  2. Pointer problem in opening a file
    By LAKI in forum C Programming
    Replies: 13
    Last Post: February 11th, 2004, 08:27 AM
  3. Replies: 1
    Last Post: February 8th, 2004, 01:59 PM
  4. Upload file name problem
    By clio in forum PHP Development
    Replies: 1
    Last Post: February 6th, 2004, 06:19 AM
  5. Problem with opening a file
    By Psantiago in forum C Programming
    Replies: 3
    Last Post: February 3rd, 2004, 07:31 PM

IMN logo majestic logo threadwatch logo seochat tools logo