Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP won't str_replace single quotes from database
    primarykey
    data
    text
    <p>This is really weird to explain, so here it goes...</p> <p>I'm fetching data from phpmyadmin that contains unescaped single quotes. I'm trying to convert <code>'</code> to <code>&amp;apos;</code> by using <code>Content-Type: text/html;</code> in a php header.</p> <p>In one column of the database, this is the value: <code>This year's...</code></p> <p>I set the content type to <code>&lt;?php header('Content-Type: text/html; charset=UTF-8'); ?&gt;</code></p> <p>I fetched the data with <code>mysql_fetch_assoc()</code>, so it should output, <code>This year&amp;apos;s</code>. But, it outputs <code>This year�s...</code>.</p> <p>I then manually deleted <code>This year's...</code> from the database and replaced it with the same <code>This year's...</code> (directly in the database). I set the content type to <code>text/html</code> again and got this:</p> <pre><code>This year&amp;apos;s... </code></pre> <p>That's it... this is almost imossible to explain. A single quote is submitted to the database through a form. I fetch it and set the content type to text/html and it outputs <code>'</code> as <code>�</code>. If I go into the database, manually delete the <code>'</code>, and replace it with the same <code>'</code>, it then outputs <code>&amp;apos;</code>.</p> <p>Has anyone ever experienced this weird quirk or recognize what it might be?</p> <p>UPDATE:</p> <p>The value in the database is <code>This year's</code> which was uploaded by a form. The quote is unescaped in the database. Here's how I'm fetching the data. I want the <code>'</code> to be converted to <code>&amp;apos;</code>.</p> <pre><code>&lt;?php header('Content-Type: text/html; charset=UTF-8'); include('init.inc.php'); function get_feeds() { $query = mysql_query("SELECT * FROM test ORDER BY id DESC LIMIT 1"); while($fetch = mysql_fetch_assoc($query)) { $text = $fetch['text']; echo $text; } } ?&gt; &lt;?php get_feeds(); ?&gt; </code></pre> <p>It outputs <code>This year�s</code>.</p> <p>I then delete <code>This year's</code> from the database and manually write <code>This year's</code> in it's place. It outputs this <code>This year&amp;apos;s</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload