Jump to content

[SOLVED] "decode" mysql_real_escape_string


web_master

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.