0
votes

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&ccedil; content &ccedil;;

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;

}
1
If you don't want HTML, why are you using TinyMCE at all?SLaks
Thanks for your answer Slaks. But I want html, but I also need to show this content without html tags in a case that Im doing, so Im trying to find a way to get my content from database without htmltags, to show contet without html tags!OzzC
But if you store it in the database without HTML tags, then you won't have any formatting anymore. Meaning you should not have used TinyMCE in the first place. Help us out. Not sure what you're trying to do.gwcoffey
Thanks gwcoffey, sorry, you are right, I was not very objective in my question! Now I update it, hope it helps to you understand better. If you dont understand please say, I try to explain better!OzzC

1 Answers

2
votes

You're looking for strip_tags().