Im inserting in my table news some information: Title and content.
Title works fine, but for content, Im using tinymce editor to write my content, and when I do my insert, I receive my content like this:
If I write this: Im doing a test to show you what Im getting.
I get this: <p>Im doing a test to show you what Im getting.</p
>
Do you know, how we can get text, that we write using tinymce editor, without html tags??
I already try with htmlspecialchars(), but without sucess.
This is my php, where I do my insert:
<?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();
}
}
?>
Then I have my form, my textarea have class="tinymce" because Im using here this plugin:
<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>
This is becauase I want to using jQuery autocomplete, and I want to show title of my news but also the content in autocomplete.
But as I have my content saved in database with html tags, when I start writing, my autocomplete results appears like:
Title - ;p><span>Contentç content ç;
This is my 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;
}