Re: Reading files in PHP 5.3.0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



--- On Thu, 9/10/09, Steve Brown <sbrown25@xxxxxxxxx> wrote:

> From: Steve Brown <sbrown25@xxxxxxxxx>
> Subject:  Reading files in PHP 5.3.0
> To: php-general@xxxxxxxxxxxxx
> Date: Thursday, September 10, 2009, 4:13 PM
> I've been beating my head against a
> wall all day and can't figure this
> one out.  The code below worked perfectly in
> PHP5.2.4.  However, I
> recently upgraded to PHP5.3.0 and this code no longer
> works.
> 
> The function below accepts the path to a text file
> containing headers
> from a cUrl session (example attached).  Basically
> this function opens
> to log file, looks for certain headers and captures some
> information
> from that line.  When called on the attached file (or
> any log file for
> that matter), the following is output:
> 
> array(2) {
>   ["ResponseCode"]=>
>   NULL
>   ["ErrorMessage"]=>
>   NULL
> }
> 
> Which means that nothing is getting read from the file.
> 
> Now, I'm going to qualify all of this by saying I'm running
> OSX Snow
> Leopard, so I'm fully prepared to believe that Apple fucked
> something
> up in it, as they have done to third party packages on
> other occasions
> in the past.  Well... to be fair, they don't usually
> fuck up third
> party packages, rather they introduce "enhancements" to the
> OS that
> prevents certain packages from working correctly and could
> care less
> that they broke it.
> 
> So did anything change in PHP5.3.0 that would preclude the
> code below
> from working?  Am I going crazy?  Or did Apple
> f*@# something up in
> this release?
> 
> Thanks,
> Steve
> 
> BEGIN CODE
> ==========
> function parseResponseHeaders($header_file) {
>     $http_found = $error_found = false;
>     $http_reponse = $error_message = NULL;
> 
>     $response = array();
>     $response['ResponseCode'] = NULL;
>     $response['ErrorMessage'] = NULL;
> 
>     if (!is_file($header_file) ||
> !is_readable($header_file)) {
>         return $response;
>     }
> 
>     $fin = fopen($header_file, 'r');
>     while ($line = fgets($fin)) {
>         var_dump($line);
> 
What does var_dump($line); tell you?

Regards,
Tommy

>         if (substr($line, 0,
> 4) == 'HTTP') {
>            
> $line_explode = explode(' ', $line);
>            
> $response['ResponseCode'] = preg_replace('/\D/', '',
> $line_explode[1]);
>             if
> ($response['ResponseCode'] != 100) {
>            
>     $http_found = true;
>             }
>         }
> 
>         if (substr($line, 0,
> 16) == 'X-Error-Message:') {
>            
> $line_explode = explode(' ', $line);
>            
> array_shift($line_explode);
>            
> $response['ErrorMessage'] = join(' ', $line_explode);
>            
> $error_found = true;
>         }
>     }
>     fclose($fin);
> 
>     var_dump($response);
>     return $response;
> }
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux