Andrew Chamberlain
Andrew Chamberlain

Reputation: 107

Save Special Character into Database

I am currently using html and php for my site but I have this problem while saving in textarea.

Everytime I use a different font with special character like ' and " it saves like � (a black diamond with question mark inside). This usually happens when I copy a text from other site or when I copy a text document then paste it but when I type in the textarea it works fine.

sample:

don�t take no for an answer and are individuals who care about

Here is my html code

    <form action="savepost.php" method="POST">
    <fieldset style="width:600px; height:580px">
    <br><strong>Title</strong> <input id="posttitle" name="posttitle" type="text">
    <br><br><strong>Content</strong>
    <br><textarea id="postform" name="postform" style="width:600px; height:450px; resize: none"></textarea>
    <br><input type="submit" value="Post" id="postbutton"/>
    </fieldset>
    </form>

Mysql Insert

    $title = strtolower(mysql_real_escape_string($_POST['posttitle']));
    $post_title = preg_replace('/[^a-zA-Z0-9\s]/','', $title);
    $timestamp=time(); 
    $post = $_POST['postform'];

    $newtitle= preg_replace('/\\s+/', ' ',$post_title);
    $striptitle = trim($newtitle, ' ');
    $url = strtolower($timestamp.'/'.str_replace(" ", "-", $striptitle));

    mysql_query("INSERT INTO blog (title, url, timestamp, post) VALUES ('$title', '$url', '$timestamp', '$post')");

what could be the problem here?

Upvotes: 0

Views: 1581

Answers (2)

austin
austin

Reputation: 5866

Are you copying some of this text from Microsoft Word? By default, Word will change your regular "straight" quotes into "curly" quotes. There's a way to turn this feature off. To fix the text you have, you might have to do a find/replace.

Upvotes: 0

Geek Num 88
Geek Num 88

Reputation: 5312

This is an character encoding issue - if you are copying the content from a desktop program (MS Word) then Word puts in the angled quote not a straight quote, but if the HTML page is not in the correct encoding to display that character it will show like above.

try looking in the header of your page for

<meta charset="utf-8" />

or something similar

if it is not utf-8 or missing try changing it and see what happens.

Upvotes: 1

Related Questions