[thelist] Removing nl and cr from Excel file

David Kutcher david_kutcher at hotmail.com
Thu Mar 28 11:10:02 CST 2002


function format_text($text){
 // Change any "<", and ">" their equivalent HTML entities
 $text = htmlspecialchars($text);
 // Strip out carriage returns
 $text = ereg_replace("\r","<br>",$text);
 // Handle line breaks
 $text = ereg_replace("\n","<br>",$text);
 // Handle double breaks
 $text = ereg_replace("<br><br>","<br>",$text);
 // Handle tabs
 $text = ereg_replace("\t","<tab>",$text);
return $text;
}

That changes your stuff.  You'll notice I did <tab>

I then use the following to parse the info:

$str1 = "<tab>";
$str2 = "<br>";

$numOccur1 = substr_count($mass, $str2) + 1;  // I think the +1 is an
idiosyncracy to my project...
 $rowofstuff= split($str2, $mass);
 echo "number of entries:".$numOccur1;

 for ($a=0; $a <$numOccur1; $a++)
 {
 $spew = $rowofstuff[$a];
 $apiece = split($str1, $spew);


Yes, this isn't the complete picture, and some things I wrote out the long
way to make them understandable, but that should do what you're asking.



More information about the thelist mailing list