function RemoveWhiteSpaces($str = '')
  $search = array ("'([\r\n])'");
  $replace = array ("\n");
  $str = preg_replace ($search, $replace, $str);
  return $str;

Just a thought:

1. Read contents of the file (file() and implode() in php) so that the
contents are contained in an array
2. foreach (lines as linenum => line) line = RemoveWhiteSpaces(line);
3. fwrite back to file

that's a rough idea..

hope it helps,

nadim attari

This may not be exaxtly PHP-DB related but it is a result of screwing
something up <grin>.

I pulled a bunch of data from a DOS formatted tab seperated file and now I
dumping back out into a text file (on linux).

So, as you can imagine, I ended up with a bunch of ^M throughout the file.
plan on fixing this.  The solution is easy enough.  I just need to remember
to open the text files in vim and save as unix files.

However, I now have an immediate need.  I want to open these five files in
and find and replace the ^M in every instance.  I know how to find and
replace (:g/find//s/replace/g).  But I cannot get the ^M in the string.  If
actually hit <ctrl-m> it reads as a return; if I type ^M using the shift-6
then it looks for the actual characters.

Can anyone help?

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to