Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England
    Posts
    172
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why does this error occur ?

    PHP Code:
    <?
    $lines 
    file('http://www.url.com');
    $lines2 strip_tags($lines);

    foreach (
    $lines2 as $line) { echo $line; }
    ?>
    Warning: Invalid argument supplied for foreach() in /home/domains/domain/user/htdocs/page.php on line 5
    Why ?
    \o/

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I suppose that $lines2 is a string and not an array. Foreach() iterates an array.

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, $lines2 is just a plain ole' variable. Foreach is used with arrays and that is not an array.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $lines file('http://www.url.com');
    foreach (
    $lines as $line) { echo strip_tags($line); } 
    or

    PHP Code:
    $file file_get_contents('http://www.url.com');
    echo 
    $file
    or if you still need to parse line by line (for numbering perhaps)

    PHP Code:
    $file file_get_contents('http://www.url.com');
    $lines explode("\n",str_replace("\r",'',$file)); 
    //the str_replace sorts out windows linebreaks

    foreach ($lines as $line) {
    echo 
    $line."\n"//the \n is important as explode strips the line breaks

    There ya go, one of them should be what you need.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)


  •  

    Posting Permissions

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