web_master Posted April 18, 2009 Share Posted April 18, 2009 Hi, when I put text into database I use mysql_real_escape_string. So the doublequotes looks like: \"sometext\". How can I replace to be like: „sometext” The first problem for me is in replace: find begin and end of quotes, because its a same on a begin and on end of word... Can You help me How can I replace these quotes??? this work for me: $NewsTexT = str_replace('\"', '„', $NewsTexT); but how can I "close" quotes to looks like this: „sometekst” thanks, T Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/ Share on other sites More sharing options...
jackpf Posted April 18, 2009 Share Posted April 18, 2009 $string = preg_replace('/\\\"(.*?)\\\"/', ',,$1\'\'', $string); Something like that. Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/#findComment-813102 Share on other sites More sharing options...
mrMarcus Posted April 18, 2009 Share Posted April 18, 2009 using mysql_real_escape_string() only adds slashes when the query is in progress and, if used correctly, strips the slashes before inputted the values into the db. so, if you're seeing slashes on your inputted value's in the db, there's something else going on. seems as though you're just adding slashes and mysql_real_escape_string() is not setup. you have some code as to what you are doing to your inputted data. Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/#findComment-813106 Share on other sites More sharing options...
web_master Posted April 18, 2009 Author Share Posted April 18, 2009 $string = preg_replace('/\\\"(.*?)\\\"/', ',,$1\'\'', $string); Something like that. ok, please give me some explantion, because I cant understand ... where can I put „ („) ” (”) Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/#findComment-813108 Share on other sites More sharing options...
jackpf Posted April 18, 2009 Share Posted April 18, 2009 Oh, my bad $string = preg_replace('/\\\"(.*?)\\\"/', '„$1”', $string); Like that. But yeah, you shouldn't actually have slashes in your database. Do you have magic quotes turned on? Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/#findComment-813114 Share on other sites More sharing options...
web_master Posted April 18, 2009 Author Share Posted April 18, 2009 well I dont know is magic quotes turned on or off, Ill try this script, but... $string = preg_replace('/\\\"(.*?)\\\"/', '„$1”', $string); what is $1 ? because in text I have "randomly" lots of words with quotes... can I do this: $string = preg_replace('/\\\"(.*?)\\\"/', '„(.*?)”', $string); Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/#findComment-813119 Share on other sites More sharing options...
web_master Posted April 18, 2009 Author Share Posted April 18, 2009 oh, ITS WORK! $string = preg_replace('/\\\"(.*?)\\\"/', '„$1”', $string); THnx... Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/#findComment-813126 Share on other sites More sharing options...
mrMarcus Posted April 18, 2009 Share Posted April 18, 2009 thing is, you're going about this the wrong way and it could come back to bite ya later on. let's say magic_quotes gets turned off on your server, now you're stuck with a piece of code that might end up doing something you don't want it to do. create a function that checks if magic_quotes are on : function sanitize ($input) { if(get_magic_quotes_gpc()) { //check if magic_quotes is on; $input = stripslashes($input); //it is, so strip any slashes and prepare for next step; } //if get_magic_quotes_gpc() is on, slashes were already stripped .. if it's off, mysql_real_escape_string() will take care of the rest; $output = mysql_real_escape_string($input); return $output; } and then use the function in your queries : sanitize($string) setting up a function allows for greater flexibility down the road with your code. Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/#findComment-813132 Share on other sites More sharing options...
web_master Posted April 18, 2009 Author Share Posted April 18, 2009 thing is, you're going about this the wrong way and it could come back to bite ya later on. let's say magic_quotes gets turned off on your server, now you're stuck with a piece of code that might end up doing something you don't want it to do. create a function that checks if magic_quotes are on : function sanitize ($input) { if(get_magic_quotes_gpc()) { //check if magic_quotes is on; $input = stripslashes($input); //it is, so strip any slashes and prepare for next step; } //if get_magic_quotes_gpc() is on, slashes were already stripped .. if it's off, mysql_real_escape_string() will take care of the rest; $output = mysql_real_escape_string($input); return $output; } and then use the function in your queries : sanitize($string) setting up a function allows for greater flexibility down the road with your code. OK, its a lots a things that I dont know yet about a PHP, Im so glad, that I can get a help here - sometimes I need a better (more) explanation, because I can understand some scripts yet. I dont want allways only a script, because If I cant understand how its works I will ask things that I dont need to ask... But You people are great, help me lots! Thanx!!! Ill try to do my best, to make a homepages w3c "compatible", and also writable for a blind people, and also to texts looks good, use tipography right "quotes" too. I work on my (born)willage site now: www.csantaver.eu so I can do it best I can! Thanks again, Tivadar Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/#findComment-813138 Share on other sites More sharing options...
jackpf Posted April 18, 2009 Share Posted April 18, 2009 There actually isn't much point in making an entire function to check for magic quotes if you're on apache. I don't think people realise that you can just turn it off with a php_flag in .htaccess But yeah, definitely turn it off. Link to comment https://forums.phpfreaks.com/topic/154630-solved-decode-mysql_real_escape_string/#findComment-813145 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.