replace <br /> tag inside textarea
Posted: Thu Aug 09, 2007 6:12 am
I need to replace the <br /> tag with chr(10) but only inside the <textarea>...</textarea> tag
Any ideas?
Any ideas?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
louie35 wrote:I need to replace the <br /> tag with chr(10) but only inside the <textarea>...</textarea> tag
Any ideas?
Code: Select all
$data = preg_replace('@(<|>)br\s*/?(>|<)@', "\n", $data);
echo "<textarea>$data</textarea>";Code: Select all
..louie35 wrote:I need to replace the <br /> tag with chr(10) but only inside the <textarea>...</textarea> tag
Any ideas?
Code: Select all
$re = <<<RE
~
<br>
(?=
(
(?<! <textarea)
.
)*
</textarea>
)
~six
RE;
$test = "
keep this <br> and this <br>
remove <textarea name=foo><br> and this <bR> and that <Br></textarea>
keep <br> and <BR>
";
echo preg_replace($re, "REPLACED", $test);Code: Select all
syntax error, unexpected T_SLthe token T_SL stands for <<louie35 wrote:syntax error, unexpected T_SL
Code: Select all
$re = '~
<br\s*/?>
(?=
(
(?<! <textarea)
.
)*
</textarea>
)
~six';