[英]how to insert and display the enter key or new line from codeigniter to database using textarea
I'm using a textarea in my html and I also want to store my inputted word on my database by using codeigniter. 我在我的HTML中使用textarea,我也希望使用codeigniter将输入的单词存储在我的数据库中。 for example if i entered the word "Hello" and the next line is "World"
例如,如果我输入单词“Hello”,下一行是“World”
like 喜欢
Hello
World
view 视图
<textarea name=text></textarea>
and before passing it to the controller this is my javascript 在将它传递给控制器之前,这是我的javascript
function add_work_experience()
{
var P1 = document.getElementById('company');
var P2 = document.getElementById('job_title');
var P3 = document.getElementById('text');
var P4 = document.getElementById('date');
var P5 = document.getElementById('description');
if (P1.value != "" && P2.value != "" && P3.value != "" && P4.value != "" && P5.value != "")
{
var data = P1.value + "|" + P2.value + "|" + P3.value
P1.value = "";
P2.value = "";
P3.value = "";
swoosh(data, path+'swoosh_employee/swoosh_work_experience', 'workexperiencedv');
}
controller,, let's say that the variable $P3 is the textarea 控制器,让我们说变量$ P3是textarea
parse_str($_SERVER['QUERY_STRING'],$_GET);
$data = $_GET['h'];
list($P1,$P2,$P3) = explode("|", $data);
$this->emp->add_word($P1, $P2, $P3);
model 模型
public function add_word($text)
{
$data = array ('text' => $text);
$this->db->insert('word', $data);
}
and by displaying it 并通过显示它
<?php echo nl2br($text);?>
but it is not working. 但它不起作用。 Is there something that i will do on my mysql server?
我会在我的mysql服务器上做些什么吗? or in my codeigniter?
还是在我的codeigniter? or in my php?
还是在我的PHP? help.
救命。 i dont know what to do.
我不知道该怎么办。
尝试使用nl2br将textarea中的新行转换为br标记:
$text = nl2br($this->input->post('text'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.