|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
remove newline characters from a string
Hello,
What is the easiest method to remove newline characters from a string? Basically, I'd like it to function like this: $newstring = rmNewline($oldstring); The newstring should now have no newline characters '\n' Thanks! |
|
#2
|
||||
|
||||
|
PHP Code:
__________________
I'm thuper, thanks for asking. Do not ask how much you should charge for your work. || Acceptable use policy || Please help us to save Ana It lives! http://www.stephenphilbin.com/ (Well it kinda' does anyway). My portable colour selection tool |
|
#3
|
|||
|
|||
|
Worked flawlessly! I appreciate your assistance. Thank you very much. I knew there must be some library method so I wouldn't have to reinvent the wheel. thanks for the extra help with the tricky syntax too that would have got me next. I recognize the 2nd and 3rd parameters but the 1st one has some tricky syntax. You da man!
|
|
#4
|
||||
|
||||
|
or you could go the less overhead route (not using the reg_ex engine) and simply use trim...
PHP Code:
__________________
- My Home - Resources for PHP and MySQL :: Please Use The Proper Tags to Format Your Code, PLEASE! |
|
#5
|
||||
|
||||
|
Quote:
PHP Code:
PHP Code:
__________________
"That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett freelancer.internet.com Email me |
|
#6
|
||||
|
||||
|
Quote:
I didn't even think about that scenerio.
__________________
- My Home - Resources for PHP and MySQL :: Please Use The Proper Tags to Format Your Code, PLEASE! |
|
#7
|
||||
|
||||
|
Actually, you both had good points. I've been arseing about with preg_replace() so much lately I'd forgotten str_replace() and str_ireplace() even existed. Both of those are faster and less "cpu expensive" than preg_replace, but Zooper-Nog here also pointed out that there may also be newlines with no space characters on either side of it. Applying my response to such a case would cause the words of either side to get concatenated, which wouldn't be too helpful. To fix such a problem we would have to chuck str_replace() and str_ireplace out in favour of preg_reaplace, but I lack the know-how to complete the function. I'll write the function as much as I can, but you'll have to wait for someone more knowledgeable than I to complete it.
Here goes: PHP Code:
Oh yeah, ya might wanna rename the function to something slightly more paractical too.
__________________
I'm thuper, thanks for asking. Do not ask how much you should charge for your work. || Acceptable use policy || Please help us to save Ana It lives! http://www.stephenphilbin.com/ (Well it kinda' does anyway). My portable colour selection tool |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|