You are here: Re: [PHP] Stripping control M character (^M) « PHP « IT news, forums, messages
Re: [PHP] Stripping control M character (^M)

Posted by Philip Hallstrom on 09/07/05 23:23

> Hello All,
>
> I'm having some issues with carriage returns. Specifically the control M
> character (^M). I have attempted to clean and validate the file I'm
> creating. Here's the code.
>
> while ($row = mysql_fetch_array($result)){
>
> // assign and clean vars
> $artist = trim($row[artist]);
> $tdDate = trim($row[start_date]);
> $venue = trim($row[venue]);
> $city = trim($row[CITY]);
> $state = trim($row[STATE]);
> $country = trim($row[COUNTRY]);
> $tdId = trim($row[td_id]);
>
> // create string
>
> $line = "$artist|||$tdDate||$venue|$city|$state|$country|$tdId\n";
>
> // validate the string
>
> if(preg_match("/.*.|||.*.||.*.|.*.|.*.|.*.|.*.n\//", $line)){
> // record is correct so write line to file
> fwrite($handle,$line);
> }
> }
>
>
> So ^M slips right by trim and my preg_match line.

Where is the carriage return appearing in your line of output? Trim
will remove these, but only at the beginning/end of a string so if $artist
= "Paul\rNowosielski" that won't get cleaned up...

Maybe run them through ereg_replace() using "[\n\r]" as a pattern?

-philip

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация