phrak Posted April 1, 2006 Share Posted April 1, 2006 I'm sure this has probably been asked a zillion times but the search wasn't too helpful, so please be gentle with the flames.I'm a complete php newb and I'm running an eve killboard, that takes a killmail, parses it into strings, and uploads the data to a mysql database. The problem is whenever the killmail contains an apostrophe, it is either read incorrectly and then screws up the database entry or it isn't read at all. I know that you have to put a slash in front of the apostrophe, but is there a way to make the parser check the string for apostrophes and then have it put the slash in, or do I have to tell everyone who uses this php ap to put a slash in front of their apostrophes or ignore them altogether? Link to comment https://forums.phpfreaks.com/topic/6347-apostrophes-in-strings/ Share on other sites More sharing options...
Zane Posted April 1, 2006 Share Posted April 1, 2006 go to [a href=\"http://php.net/addslashes\" target=\"_blank\"]http://php.net/addslashes[/a]and learn the functionit should fix it all up Link to comment https://forums.phpfreaks.com/topic/6347-apostrophes-in-strings/#findComment-22930 Share on other sites More sharing options...
coldkill Posted April 1, 2006 Share Posted April 1, 2006 Try [code]str_replace("'", "\'", $text);[/code]That will find any " ' "'s in $text and replace them with " \' ".There is always addslashes which is the default PHP function (from 3 onwards) to add a slash in front of any ' and " characters. But you have to use stripslashes when you want to display the string. Link to comment https://forums.phpfreaks.com/topic/6347-apostrophes-in-strings/#findComment-22931 Share on other sites More sharing options...
wildteen88 Posted April 1, 2006 Share Posted April 1, 2006 actually you dont have to use stripslashes if you use addslashes as PHP will strip them out automatically as it'll see you are eascaping a single/double quote or characters. Link to comment https://forums.phpfreaks.com/topic/6347-apostrophes-in-strings/#findComment-22956 Share on other sites More sharing options...
annihilate Posted April 1, 2006 Share Posted April 1, 2006 I include the following code on every page, and for any database queries with form data, apply mysql_real_escape_string to the form variables. You don't need to apply any functions to retrieve from the database, the text in there wil be exactly as you submitted it. [code]if ( get_magic_quotes_gpc() ) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; }$_POST = stripslashes_deep($_POST);$_GET = stripslashes_deep($_GET);$_COOKIE = stripslashes_deep($_COOKIE);}[/code] Link to comment https://forums.phpfreaks.com/topic/6347-apostrophes-in-strings/#findComment-22966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.