weird error with file() and implode()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Kay

    weird error with file() and implode()

    Maybe I don't understand how to use this yet, but I was using (example):

    $html = implode('', file('http://www.mysite.com/transbar.html') );
    echo $html;


    This works.

    But if I try it on a .php file:


    $html = implode('', file('http://www.mysite.com/transbar.php')) ;



    I get this error:

    Warning: file("http://www.mysite.com/transbar.php") - Success in
    /home/cust1/usr2345/html/setuptransbar.p hp on line 47

    Warning: Bad arguments to implode() in
    /home/cust1/usr2345/html/setuptransbar.p hp on line 47


    Can't you read in a php file this way?

    Thanks,
    --
    Stephen Kay
    Karma-Lab sk@karma-lab.NOSPAM.com
    ^^^^^^^


  • Colin McKinnon

    #2
    Re: weird error with file() and implode()

    Stephen Kay wrote:
    [color=blue]
    >
    >
    > $html = implode('', file('http://www.mysite.com/transbar.php')) ;
    >
    >
    >
    > I get this error:
    >
    > Warning: file("http://www.mysite.com/transbar.php") - Success in
    > /home/cust1/usr2345/html/setuptransbar.p hp on line 47
    >
    > Warning: Bad arguments to implode() in
    > /home/cust1/usr2345/html/setuptransbar.p hp on line 47
    >
    >
    > Can't you read in a php file this way?
    >[/color]

    Apparently not - I presume the script doesn't generate any output and you
    really want the source?

    C.

    Comment

    • diogo86@gmail.com

      #3
      Re: weird error with file() and implode()

      i agree that the script may not be genarating any output. you check it
      doing this:

      echo '<pre>'; print_r(file('h ttp://www.mysite.com/transbar.php')) ; echo
      '</pre>';

      it shows up the array you got from this request. however you won't be
      able to read the source once you're making a http request.

      and if you want the output as a string you should use
      file_get_conten ts().

      Comment

      • Stephen Kay

        #4
        Re: weird error with file() and implode()

        in article 1143671863.9980 06.125890@t31g2 00...legr oups.com,
        diogo86@gmail.c om at diogo86@gmail.c om wrote on 3/29/06 5:37 PM:
        [color=blue]
        > and if you want the output as a string you should use
        > file_get_conten ts().[/color]

        Thanks, I would if my ISP was using PHP >= 4.3. It's using 4.1.


        --
        Stephen Kay
        Karma-Lab sk@karma-lab.NOSPAM.com
        ^^^^^^^


        Comment

        • Stephen Kay

          #5
          Any efficiency difference between fopen() etc. and file()?


          I'm wondering if there is any advantage one way or the other to these two
          methods of reading an html file:

          1. using fopen and friends:

          $myFile = "http://www.example.com/page.html";
          $fh = fopen($myFile, 'r');
          $content1 = fread($fh, filesize($myFil e));
          fclose($fh);


          2. using imploed, and file:

          $content1 = implode('', file("http://www.example.com/page.html"));


          They both seem to work equally well, but the number 1. seems to be more
          robust with different file types...


          Note: I can't use file_get_conten ts() because my ISP's PHP version is 4.1 or
          so.


          --
          Stephen Kay
          Karma-Lab sk@karma-lab.NOSPAM.com
          ^^^^^^^


          Comment

          Working...