...

View Full Version : extract \n between code then replace remaining \n with <br>



tylerjca
02-18-2006, 04:48 AM
Hi. What i'm trying to do is take out any \n (line break) from between certain tags such as <style> and </style> and then after that, replace all the remaining \n with <br>

so far all i know how to do is the <br>


<?php
$my_string = "<style>
body{
color:#00f;
background-color:#000;
}
</style>

Then this is the
rest of the
string with
random
line breaks";

$text = preg_replace("(\r\n|\r\n)","<br />",$my_string);
?>

The problem with this is that the <style> tag doesn't do what it should because the script puts <br /> where they should not be

So how would I make it so the \n between <style> and </style> are replaced with just " " (just as an example)

Thanks in advance:)

Zegg90
02-18-2006, 03:24 PM
Hmm.. you could do something like this:


<?php
$my_string = "<style>
body{
color:#00f;
background-color:#000;
}
</style>

Then this is the
rest of the
string with
random
line breaks";

$var1 = explode("</style>", $my_string);
$text1 = preg_replace("(\r\n|\r\n)","",$var1[0]);
$text2 = nl2br($var1[1]);
$my_string = $text1."</style>".$text2;
?>



It might and might not work... It's just an idea, I haven't tested this code.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum