Re: Removing a return character

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

 



All the suggestions made earlier make sense.  You could use a regular expression or a str_replace() if you knew what you were looking for.  And as someone mentioned, depending on your data set, you might want to use trim() (or the left or right variety thereof).

When dealing with a single line of data with "something funky" at the end, I'd usually end up using trim() because it removes white spaces, tabs, new lines, carriage returns, nulls and tabs from the string and that covers most of what I wouldn't want to be displaying or parsing in the projects I've worked on in the past.

If there's a chance that you will have any of those characters that you'd WANT to keep, then you can go with one of the other methods, or use the option parameters for trim() to tell it exactly what to trim.  Again, this will only remove items from the beginning and end of the string/line, not the middle.  So in some cases, this will be preferable to a str_replace() and simpler than using a regex (which could probably emulate trim() or any other replacement function... just need to know regex syntax. I think trim() is more intuitive for something this simple).

If you're still getting odd stuff, try going through your string and displaying the ord() of each character.  This will show you the ascii (decimal) value for that character.  If it's not a 32 (white space), 9 (tab), 10 (new line), 13 (carriage return), 0 (null), or 11 (vertical tab apparently), then you could use str_replace or use trim() with it's optional parameters to remove the offending character.

See the documentation for trim() here for more info:
http://us2.php.net/manual/en/function.trim.php

Good luck!

-TG

= = = Original message = = =

Hi,

I have a system that scans through a CSV File and inserts each row into a 
database. I have just noticed that some rows have a return character in 
them - a small square - and this is causing errors in the mysql query.

Does anyone know how I can remove such chracters?


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
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