Paul Godard wrote:

> Hi
> 
> I am trying to get php 4.1.2 to read a Mac file (exported from
> FileMaker Pro) and split it into different lines  using the following
> but php does not recognize the end of line.  For some tech reason I
> cannot upgrade php now but I need to be able to read my Mac files
> now.  What is the easiest : edit the Mac file and replace the end of
> line or modify the script below?  In any case I need help to know
> exactly what to do.
> 
>   // first read the entire file
>    $file = file($Export_ImageBank);
> 
>    // process each line in turn
>    foreach ($lines as $line_num => $line) {
> 
> 
> // first split tab-separated fields
> 
list($Image_ID,$Mark_Check,$Image_Good,$Image_VeryGood,$Image_ShortCodeOrgan,$Image_Number,$Image_SubFolder,$Image_Format,$Image_MaxPxWidth,$Image_MaxPxHeight,$Image_Year,$Image_Month,$Image_Subject,$Image_CodeCountry,$Image_Region,$Image_Location,$Image_Collection,$Image_Caption,$Image_CodePrice)
> = explode("\t", $line);
> 
> Please email me directly at [EMAIL PROTECTED]  Thanks.
> 

Something like this should work for text files from any platform, the Vertical 
Tab conversion is filemaker specific and only really needed if there are line 
breaks embedded in the file maker fields.

// Read the entire file as a string
$fp = fopen($Export_ImageBank", "r");
$file_buffer = fread($fp, filesize($Export_ImageBank));
fclose($fp);

// Convert DOS/Windows line breaks (\r\n) to UNIX line breaks (\n)
$file_buffer = str_replace("\r\n", "\n", $file_buffer);

// Convert MAC line breaks (\r) to UNIX line breaks (\n)
$file_buffer = str_replace("\r", "\n", $file_buffer);

// Break the string up into an arrray of lines
$file = explode("\n", $file_buffer);

// process each line in turn
foreach ($lines as $line_num => $line) {
        // Unfilemaker each line (Vertical Tab --> \n), filemaker uses Vertical Tabs
        // to represent line breaks inside fields, so we convert them to \n
        $line = str_replace("\013", "\n", $line);

        ...

-- 
Travers Carter - Noggin - http://www.noggin.com.au/


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

Reply via email to