replace <br /> tag inside textarea
Moderator: General Moderators
replace <br /> tag inside textarea
I need to replace the <br /> tag with chr(10) but only inside the <textarea>...</textarea> tag
Any ideas?
Any ideas?
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: replace <br /> tag inside textarea
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>";Thanks for the reply but is not what i needed - sorry my bad
i have the data in the db and some is enclosed between the which i replace with <textarea ..>...</textarea>
after this i need to replace the <br /> tags with chr(10) but only whats inside the <textarea>..</textarea> tags
i have the data in the db and some is enclosed between the
Code: Select all
..after this i need to replace the <br /> tags with chr(10) but only whats inside the <textarea>..</textarea> tags
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
Re: replace <br /> tag inside textarea
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);how that's that work cause it gives me an error:
haven't seen this type of coding before.
Code: Select all
syntax error, unexpected T_SLthe token T_SL stands for <<louie35 wrote:syntax error, unexpected T_SL
But stereofrog wrote <<< which is a T_START_HEREDOC
One suggestion: use <br\s*/?> instead of <br> in the expression and it will also match <br />
If you can't get the heredoc syntax to work try
Code: Select all
$re = '~
<br\s*/?>
(?=
(
(?<! <textarea)
.
)*
</textarea>
)
~six';- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am