English 中文(简体)
产出
原标题:outputting after text is decoded - PHP

I am building an application where users can enter a note into a textarea. The note is then encoded when entered into the database. When I decode the returned value, the nl2br function isn t working. It isn t replacing the with the br tag. When not encoding/decoding text, it works.

我正在使用以下代码对我的信息进行编码/编码:

如果我进入一个文本领域:

Hello  
World

It encodes it, and then returns when decoded

Hello
World.

I can do a str_replace, but as I come to understand, depending on the browser, a textarea may use or instead of .

Not sure what a good solution is... please help! Thank you!

最佳回答

如果您正在转换成“复制件;文本处理器”,则不使用“复制件”;

If you are converting text to be placed in a text area, use...

str_ireplace("
", "
", $db_string); //or something similar

如果您将案文转换成一个文本领域,则使用......

str_ireplace(array("
", "
", "
"),  <br /> , $db_string);

Separate browsers use whatever, but I believe they all can read just " ". However on a side note, the operating system determines " " vs " ". Just use " ". So replace " " with " ". Or just leave " ", use either, as long as you don t put br tags into your textarea tags you ll be all set.

Mac = Linux = Windows =

问题回答

I have checked your decoded string Hello World. in windows operating system using zend studio 7.2.0. I found nl2br() is working fine in both case and . You should double check your decoded string. May be you are doing addslashes() before encoding it.If so then you have to use stripslashes() before using nl2br().

您可使用<代码>stripslashes($text)来脱覆。 然而,我建议说明为什么会增加鞭.。 您是否使用<条码>。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签