当我试图在php中回显json时,它返回\ n \ r \ t。我如何删除它们?Json返回字符
这里是我的代码:
ob_start();
$this->load->view('competition/template',$q);
$content = ob_get_clean();
$data['content'] = $content;
echo json_encode($data);
而且我越来越:
</table>{"ok":1,"content":"<table>\r\n <tr>\r\n\t <td>Competitor name<\/td>\r\n\t <td><input type=\"text\" name=\"competitor_name[2]\" \/><\/td>\r\n <\/tr>\r\n <tr>\r\n <\/tr>\r\n <tr>\r\n <\/tr>\r\n <tr>\r\n <\/tr>\r\n<\/table>"}
这是template.php文件中:
<table>
<tr>
<td><?php echo $this->__('Competitor name');?></td>
<td><input type="text" name="competitor_name[<?php echo $id?>]" /></td>
</tr>
</table>
str_replace函数或preg_repalce之后,我越来越:
{"ok":1,"content":"<table> <tr> <td>Competitor name<\/td> <td><input type=\"text\" name=\"competitor_name[1]\" \/><\/td> <\/tr> <\/table>"}
现在我的问题是\。
谢谢。
好的,我找到了anwser。这是它:
$content = preg_replace("@[\\r|\\n|\\t|\\/|\\\"][email protected]", "", $content);
但我不知道为什么我得到这个问题。
你想删除或替换它们有效的HTML(''
)? – ManseUK 2012-03-19 13:06:13
听起来像他们来自模板...你*可以*只str_re_replace他们出我想 – 2012-03-19 13:06:17
我想要删除他们 – Vahan 2012-03-19 13:11:55