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 7 of 7
  1. #1
    Regular Coder MrBiggZ's Avatar
    Join Date
    Apr 2005
    Location
    Indianapolis IN
    Posts
    343
    Thanks
    44
    Thanked 2 Times in 2 Posts

    fopen on a webpage doesn't yield the array

    Greetings!

    This is my goal to be able to read a webpage into a file then strip out the addresses of the locations. It's so I can make POI file for my GPS.

    Now the strange thing is .. the file gets created but never gets anything put into it. The web URL is valid.

    PHP Code:
    <?php
    /***********************************************************************/

    ini_set('display_errors'1);
    ini_set('error_reporting'E_ALL);
    ini_set('display_startup_errors'1);

    /***********************************************************************/

    $filename "kroger.txt";
    $web_url    "http://services.kroger.com/StoreLocator/StoreLocatorResults.aspx?AddressLineOne=&AddressLineTwo=&City=Indianapolis&State=IN&ZipCode=&Radius=50&Banner=KROGER&Organics=False&OneHourPhoto=False&Pharmacy=False&Pharmacy24=False&FuelCenter=False&Bank=False&Marketplace=False&PharmacyServices=False&FluFinder=False&Generics=False";

    if (
    file_exists($filename) == FALSE
               {
                
    touch($filename);
                for (
    $i=1$i <= $pages$i++ )
                    {
                        
    $fileArray file($web_url,FILE_SKIP_EMPTY_LINES);
                        
    $fileHandle fopen($filename"a");
                        foreach (
    $fileArray as $linefwrite($fileHandle$line);
                    }
                
    fclose($fileHandle);
                }
                
    ?>
    I don't get any errors messages .. just a blank screen the file that is created is empty. I've used this same bit of code before when I was stripping out items from my youtube playlists and that works great! Is this because the website doesn't want me imposing this type of behavior on them?

    Thanks for any help! I'll keep plugging away while waiting!

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    After you run it the first time, it will never do anything again because the file already exists. It will be a blank screen no matter what happens since you don't have any output. You should include some output at least for debugging so you'll know what's going on.
    Are you a Help Vampire?

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I may be a bit blind here, where is $pages defined? Also, fclose will need to go inside the for loop.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Regular Coder MrBiggZ's Avatar
    Join Date
    Apr 2005
    Location
    Indianapolis IN
    Posts
    343
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    I may be a bit blind here, where is $pages defined? Also, fclose will need to go inside the for loop.
    Guess I was too! Blind that is! Grrrrr!

    PHP Code:
    <?php
    /***********************************************************************/

    ini_set('display_errors'1);
    ini_set('error_reporting'E_ALL);
    ini_set('display_startup_errors'1);
    ini_set('tidy.clean_output'1);

    /***********************************************************************/

    $filename "kroger.txt";
    $web_url    "http://services.kroger.com/StoreLocator/StoreLocatorResults.aspx?AddressLineOne=&AddressLineTwo=&City=Indianapolis&State=IN&ZipCode=&Radius=50&Banner=KROGER&Organics=False&OneHourPhoto=False&Pharmacy=False&Pharmacy24=False&FuelCenter=False&Bank=False&Marketplace=False&PharmacyServices=False&FluFinder=False&Generics=False";
    sleep(10);
    $fileArray file($web_url,FILE_SKIP_EMPTY_LINES);
    $fileHandle fopen($filename"w");
    foreach (
    $fileArray as $linefwrite($fileHandle$line);
    fclose($fileHandle);
                
    ?>
    There we go! But ... it seems that page loads something and I don't what I had intended to use If you actually plug that URL in a browser you'll see the page in its complete form. Unless somebody knows a trick to get the page to load completely before loading it into the array.

    I get this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Error</title>
        <link href="/css/banner.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
    	<div id="main">
    		<div id="grayBlock">
    			<div id="header">
    				<div id="branding">
    					<img src="/SiteCollectionImages/multibanner/banner_logo_header.gif" alt="The Kroger Co Family of Stores" />
    				</div>
    			</div>
    			<div id="contentBox">
    				<div id="boxTop"></div>
    				<div class="body">
    					<h1>Error!</h1>
    					<br />
    					<p>We’re sorry, but we are unable to process your request at this time. Please try again later.</p>
    				</div>
    				<div id="boxBottom"></div>
    			</div>
    		</div>
    		<div id="clear"></div>
    		<div id="legalFooter">
    			<div class="body">
    				<div>All Comments © Copyright 2009 The Kroger Co. All Rights Reserved</div>
    			</div>
    		</div>
    	</div>
    </body>
    </html>

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The page does load before file. What it returns is the same html provided to a browser with the same input. Since the result don't match, the input must be at fault. Try playing with a combination of htmlspecialchars and urlencode on the url. If I had to guess'er, I'd say the & is the problem.
    Also, given what you are doing, I'd just use fopen (we know url is enabled), and write directly as a string using fread or fpassthru on the buffer. Much faster.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #6
    Regular Coder MrBiggZ's Avatar
    Join Date
    Apr 2005
    Location
    Indianapolis IN
    Posts
    343
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    The page does load before file. What it returns is the same html provided to a browser with the same input. Since the result don't match, the input must be at fault. Try playing with a combination of htmlspecialchars and urlencode on the url. If I had to guess'er, I'd say the & is the problem.
    Also, given what you are doing, I'd just use fopen (we know url is enabled), and write directly as a string using fread or fpassthru on the buffer. Much faster.
    Yeah .. I tried a bunch of different things all got the same results. Googled my butt off! I always ended up with that "ERROR! We're sorry, but we are unable to process your request at this time. Please try again later." I'm guessing that its because of the time it takes the search results to be posted to the page (takes a couple of seconds). Oh well!

    Hey .. you wouldn't happen to know of a way to extract the text from a PDF document would you??

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You can either read up on pdf file structure and write your own handler, or you can use php's pdf library.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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