Re: preg_replace help

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

 



Michael A. Peters wrote:
Kim Madsen wrote:
Michael A. Peters wrote on 26/01/2010 14:18:
$fixSrch[] = '/\n/';
$fixRplc[] = '[br]';

is what I need except I want it to leave anything between [code] and [/code] alone.

I figured it out before but with <element> </element> but I don't even remember what I was working on when I did that and I can't for the life of me find it now.

Just use the function nl2br()

If you wanna match "\n", you need to add a backslash before the backslash: "\\n"


No, I do NOT want to use nl2br.
For one thing, nl2br isn't xml safe so I'd have to do another preg_replace to fix that. My bbcode parser is xml safe.

For another thing, my bbcode parser doesn't like html in its input, and this needs to be done before the parser.

'/\n/','[br]'

works exactly as I want it to right now except I do not want it replace the newlines inside [code][/code] as that messes up the syntax highlighting that is then done one the code block.


I got it, though it may not be the most elegant way.

I split the input up into array and do the preg_replace on array elements that are not inside [code]. Seems to work, and also solves the other problem (other problem being proper application of strip_tags except inside [code].

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