我在表格中插入一些信息:标题和内容。
标题工作正常,但对于内容,我使用tinymce编辑器来编写我的内容,当我进行插入时,我会收到这样的内容:
如果我写这个:我正在做一个测试,告诉你我得到了什么。
我明白了这一点: <p>Im doing a test to show you what Im getting.</p
&gt;
你知道吗,我们如何获取文本,我们使用tinymce编辑器编写,没有html标签?
我已经尝试过htmlspecialchars(),但没有成功。
这是我的php ,我在其中插入:
<?php
if(isset($_POST['sendForm'])){
$f['title'] = $_POST['title'];
$f['conteudo'] = $_POST['content'];
if(in_array('',$f))
{
echo 'You need to fill all';
}
else
{
$insert = $pdo->prepare("INSERT INTO news ( title, content) VALUES (:title, :content)");
$insert->bindValue(':title', $f['title']);
$insert->bindValue(':content', $f['content']);
$insert->execute();
}
}
?>
然后我有我的表单,我的textarea有class =“tinymce”因为我在这里使用这个插件:
<form action="" method="post" enctype="multipart/form-data">
<label class="line">
<span>title:</span>
<input type="text" name="title" value="<?php if(isset($_POST['title'])) echo $f['title']; ?>" />
</label>
<label class="line">
<span>Content:</span>
<textarea name="content" class="tinymce" rows="15"><?php if(isset($_POST['content'])) echo htmlspecialchars($f['content']); ?></textarea>
</label>
<input type="submit" value="Send" name="sendForm"/>
</form>
这是因为我想使用jQuery自动完成功能,我希望显示我的新闻标题以及自动完成内容。
但因为我的内容已保存在带有html标签的数据库中,当我开始编写时,我的自动填充结果显示为:
标题 - ; p&gt;&lt; span&gt; Content&amp; ccedil;内容&amp; ccedil ;;
我的php for autocomplete:
switch($action)
{
case 'complete':
$search = isset($_GET['term']) ? $_GET['term'] : "";
$pdo = conecting();
$read = $pdo->prepare("SELECT * from news WHERE title LIKE ?");
$read->bindValue(1, "%$search%", PDO::PARAM_STR);
$read->execute();
$data = array();
while($res = $read->fetch(PDO::FETCH_ASSOC))
{
$data[] = $res['title'].'-'.$res['content'];
}
echo json_encode($data);
break;
}