I have used mysql_real_escape_string to enter info into the database but when I return the info in a query I get \\\' in the text. I have made it so that the insert query does not stop at the ' in a sentance anymore when saving as it used to. It used to stop saving he title of an article halfway through if it contained an apostrophe. That has been fixed but now I get \\\' where there is an apostrophe.
Example: Microsoft\\\'s $15 Windows 8 upgrade offer to run from June 2nd to January 31st, will include free workshops
My query code to return a list from the database looks like this: (Note that this is an excerpt so does not contain the closing of this loop)
<?php
$q2 = "SELECT * FROM ReadLater WHERE Folder_ID = 0 AND User_ID = $loggedInUser->user_id ORDER BY dt_added DESC";
$r2 = mysql_query($q2);
echo "<div id='folderstitleright'>Unread</div>";
if(mysql_num_rows($r2)>0)
{
echo "<ul id='foldersarticlelist'>";
$sr2=1;
while($row = mysql_fetch_assoc($r2))
{
echo "
<li class='box'>
etc
Any idea how to stop this? I have tested to see if magic quotes are on and they are but with the web host I have no way of turning them (that i have found, there may well be a really complicated way but I haven’t found it yet) of and they also say they ignore php flags in the .htaccess file.
I have tried to do a preg_replace of \\\' to ' but have so far been unsuccessful, from what I have tried of that it breaks the query entirely but I may well be executing it wrong or have it placed in the wrong place in the code above.
Don’t use preg_replace with this, just use str_replace.