开发者

How to 'undo' this small function in PHP?

I am using this t开发者_开发知识库o adapt my text which then gets inserted into a mysql db:

$ad_text=nl2br(wordwrap($_POST['annonsera_text'], 60, "\n", true));

When users wish to change their posting, they click a link on my page, and a form opens. In this form, the textarea where I fetch the info from mysql, I am displaying the text again. Only problem is, the text itself contains '<br>' tags. That is, it shows up EXACTLY as it looks in the mysql table field.

How can I undo the function above so that the <br> tags are removed again? Thanks


Why not insert your clean unmodified text into the database, then html-ify it only when displaying?


This will be more future-proof, I think:

$ad_text = preg_replace('/<br\s*?/?>/i', "\n", $ad_text);

You never know... the nl2br script may or may not put spaces in between the <br and the /> in the future.


A quick find and replace would do the trick:

$ad_text = str_replace('<br />', "\n", $ad_text);

...essentially replacing all found breaks with newlines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜