Technique #1
function br2newline( $input ) {
$out = str_replace( "<br>", "\n", $input );
$out = str_replace( "<br/>", "\n", $out );
$out = str_replace( "<br />", "\n", $out );
$out = str_replace( "<BR>", "\n", $out );
$out = str_replace( "<BR/>", "\n", $out );
$out = str_replace( "<BR />", "\n", $out );
return $out;
}
Converts a break tag to a newline – no matter what kind of HTML is being processed.
Technique #2
function br2nl( $input ) {
return preg_replace('/<br(\s+)?\/?>/i', "\n", $input);
}
Technique #2 will work a lot better than #1
But in #1, you could just use the first three calls and use str_ireplace() instead.
I’m suffered a lot. A used ” but I should use ‘. Could it be really a mistake?
please help me out why is “i” used in
function br2nl( $input ) {
return preg_replace(‘//i’, “\n”, $input);
}
at the end of first parameter of preg_ replace
function br2nl( $input ) {
return preg_replace('//i', "\n", $input);
}
sorry the code got messed up
to make the regex case insensitive
You can also do:
function _br2nl($input)
{
return str_replace(array("", "", "", "", "", ""),"\n", $input );
}
<pre><code>
function _br2nl($input)
{
return str_replace(array(“<br>”, “<BR>”, “<br/>”, “<BR/>”, “<br />”, “<BR />”),”\n”, $input );
}
</code></pre>
`(\s+)?` could just be `\s*`.
It seems that you just need to use the nl2br() function
thats all.
You can replace this:
With this:
Here is how I would do it:
But you should know that it won’t work on malicious input, such as:
Here is a test of such input.
is there any way to apply css style to br
this is help full. but i want to change in wordpress to . i tried remove_filter( ‘the_content’, ‘wpautop’ );
remove_filter( ‘the_excerpt’, ‘wpautop’ ); but not work
preg_replace(‘#(\s*)+#i’, “\n”, $input);