[PHP] newline and return issues in string
I have come across an issue with my string that I would like to find a faster way to resolve. It seems there are new lines and returns at different positions of the string. First I exploded on the new line explode(\n, $ string) This gave me a nice array but when I try to implode I get the new lines again. There is not a consistent position and there seems to be some hidden returns in the array as well. Is there a way, or has someone written a filter that would allow me to remove all the newlines and returns from the array or string. Understand I have resolved this issue but I think I have to be going about this the hard way because it is just too complex . FYI $filter = array(\r\n, \n, \r); str_replace($filter,,$string) ß this is useless in this situation I have tried and it does not change the string at all. Understand the newlines and returns do not display in the string as literals. Meaning you do not see /n or /r it is hidden.
Re: [PHP] newline and return issues in string
On Tue, Oct 11, 2011 at 7:58 AM, ad...@buskirkgraphics.com wrote: I have come across an issue with my string that I would like to find a faster way to resolve. It seems there are new lines and returns at different positions of the string. First I exploded on the new line explode(“\n”, $ string) This gave me a nice array but when I try to implode I get the new lines again. There is not a consistent position and there seems to be some hidden returns in the array as well. Is there a way, or has someone written a filter that would allow me to remove all the newlines and returns from the array or string. Understand I have resolved this issue but I think I have to be going about this the hard way because it is just too complex . FYI $filter = array(\r\n, \n, \r); str_replace($filter,’’,$string) ß this is useless in this situation I have tried and it does not change the string at all. Understand the newlines and returns do not display in the string as literals. Meaning you do not see /n or /r it is hidden. What about using nl2br() and then stripping out all the BR tags? -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] newline and return issues in string
-Original Message- From: Bastien Koert [mailto:phps...@gmail.com] Sent: Tuesday, October 11, 2011 8:53 AM To: ad...@buskirkgraphics.com Cc: php-general@lists.php.net Subject: Re: [PHP] newline and return issues in string On Tue, Oct 11, 2011 at 7:58 AM, ad...@buskirkgraphics.com wrote: I have come across an issue with my string that I would like to find a faster way to resolve. It seems there are new lines and returns at different positions of the string. First I exploded on the new line explode(\n, $ string) This gave me a nice array but when I try to implode I get the new lines again. There is not a consistent position and there seems to be some hidden returns in the array as well. Is there a way, or has someone written a filter that would allow me to remove all the newlines and returns from the array or string. Understand I have resolved this issue but I think I have to be going about this the hard way because it is just too complex . FYI $filter = array(\r\n, \n, \r); str_replace($filter,,$string) ß this is useless in this situation I have tried and it does not change the string at all. Understand the newlines and returns do not display in the string as literals. Meaning you do not see /n or /r it is hidden. What about using nl2br() and then stripping out all the BR tags? -- Bastien Cat, the other other white meat I tried that but same issue -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newline and return issues in string
On 11 October 2011 12:58, ad...@buskirkgraphics.com wrote: I have come across an issue with my string that I would like to find a faster way to resolve. It seems there are new lines and returns at different positions of the string. First I exploded on the new line explode(“\n”, $ string) This gave me a nice array but when I try to implode I get the new lines again. There is not a consistent position and there seems to be some hidden returns in the array as well. Is there a way, or has someone written a filter that would allow me to remove all the newlines and returns from the array or string. Understand I have resolved this issue but I think I have to be going about this the hard way because it is just too complex . FYI $filter = array(\r\n, \n, \r); str_replace($filter,’’,$string) ß this is useless in this situation I have tried and it does not change the string at all. You don't want to remove them. You want to replace them with a constant. $lines = explode(PHP_EOL, str_replace($filter, PHP_EOL, $string)); for example. -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newline and return issues in string
On 10/11/2011 04:44 PM, Richard Quadling wrote: On 11 October 2011 12:58,ad...@buskirkgraphics.com wrote: I have come across an issue with my string that I would like to find a faster way to resolve. It seems there are new lines and returns at different positions of the string. First I exploded on the new line explode(“\n”, $ string) This gave me a nice array but when I try to implode I get the new lines again. There is not a consistent position and there seems to be some hidden returns in the array as well. Is there a way, or has someone written a filter that would allow me to remove all the newlines and returns from the array or string. Understand I have resolved this issue but I think I have to be going about this the hard way because it is just too complex . FYI $filter = array(\r\n, \n, \r); str_replace($filter,’’,$string) ß this is useless in this situation I have tried and it does not change the string at all. You don't want to remove them. You want to replace them with a constant. $lines = explode(PHP_EOL, str_replace($filter, PHP_EOL, $string)); for example. try to implement a string builder using array or arrayobject and on insert; filter / replace your text / characters using regex, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] newline and return issues in string
-Original Message- From: Richard Quadling [mailto:rquadl...@gmail.com] Sent: Tuesday, October 11, 2011 9:44 AM To: ad...@buskirkgraphics.com Cc: php-general@lists.php.net Subject: Re: [PHP] newline and return issues in string On 11 October 2011 12:58, ad...@buskirkgraphics.com wrote: I have come across an issue with my string that I would like to find a faster way to resolve. It seems there are new lines and returns at different positions of the string. First I exploded on the new line explode(“\n”, $ string) This gave me a nice array but when I try to implode I get the new lines again. There is not a consistent position and there seems to be some hidden returns in the array as well. Is there a way, or has someone written a filter that would allow me to remove all the newlines and returns from the array or string. Understand I have resolved this issue but I think I have to be going about this the hard way because it is just too complex . FYI $filter = array(\r\n, \n, \r); str_replace($filter,’’,$string) ß this is useless in this situation I have tried and it does not change the string at all. You don't want to remove them. You want to replace them with a constant. $lines = explode(PHP_EOL, str_replace($filter, PHP_EOL, $string)); for example. -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea Richard I am not sure I understand what that is doing it made things 300% worse. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php