Re: Here files and backslashes

From: Date: Tue, 04 Jul 2000 16:03:12 +0000
Subject: Re: Here files and backslashes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-4817@lists.php.net to get a copy of this message
At 11:51 AM 7/4/00 -0700, J C Lawrence wrote: >Most interestingly it doesn't generate a warning for every backslash >character. In the above example is misses the first several >backslashes and generates a warning on only the strings "\|" and >"\<nl>" where <nl> is an LF (bottom of the man's shield and end of >his sword). \ is the escape character for PHP. For example, if someone wanted to print: Then the man said, "Hello". Your command would look lik: PRINT "Then the man said, \"Hello\"."; It is also used for special characters like New Line \n or Tab \t Now the weird thing that happens is, what if you wanted to print \n instead of forcing PHP to go to a new line? Well, your command would look like: PRINT "You can use the \\n sequence to force a new line."; That first \ "escapes" the second \ so it simply prints "\n". Now the cure.... The easiest command to use is addslashes(). Let's suppose a user is at a form and enters the following in a text box which is assigned the variable name Message: Then the man said, "Hello". The script that processes this form should have the following code in it: <? $MessageSlashes = addslashes($Message); // This makes turns all of the " into \" PRINT "$MessageSlases"; // This prints it out with quotes. ?> This is also important if you're saving it into a database because if the user has inputed any ' or " it will mess up your INSERT INTO query. Hope this helps, Jeff Gannaway (Now with more coffee)

« previous php.general (#4817) next »