New to php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dmwesq
Forum Newbie
Posts: 21
Joined: Wed Jan 23, 2008 4:35 pm

New to php

Post by dmwesq »

Just getting started, and as per the book I'm using, I created a simple form.

Code: Select all

 
<?php
    echo "<p>Welcome <b>".$_POST["user"]."</b>!</p>";
    echo "<p>Your message is:<br/><b>".$_POST["message"]."</b></p>";
    ?>
 
Here is what was entered in the message:

Code: Select all

 
This is a test. You're the best!!!
 
Somehow, in the output, there is a slash in the word You're:

Code: Select all

 
Welcome Dan!
 
Your message is:
This is a test. You\'re the best!!!
 
Any idea where that slash came from? It doesn't appear in the code on this page, but it does show in the browser - tried it in Firefox and Safari.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: New to php

Post by Christopher »

Your PHP configuration is probably set to add slashes to request variables. There are functions to strip slashes.
(#10850)
dmwesq
Forum Newbie
Posts: 21
Joined: Wed Jan 23, 2008 4:35 pm

Re: New to php

Post by dmwesq »

arborint wrote:Your PHP configuration is probably set to add slashes to request variables. There are functions to strip slashes.
Where would I find such a function?

More importantly, when you are not hostng the php yourself but are relying on the server of the host, how do you access files such as php.ini if need be? I see the file on the server directory, which is a Linux server. Do I need to download that file to my hard drive to edit it, and can I edit that in a Mac environment and then upload it again to the Linux-based server?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: New to php

Post by Christopher »

dmwesq wrote:Where would I find such a function?
Here
dmwesq wrote:More importantly, when you are not hostng the php yourself but are relying on the server of the host, how do you access files such as php.ini if need be? I see the file on the server directory, which is a Linux server. Do I need to download that file to my hard drive to edit it, and can I edit that in a Mac environment and then upload it again to the Linux-based server?
If you can edit the php.ini file and restart the web server, then do that. Otherwise, you can call functions within your scripts to change some settings. And there are functions like I mentioned above to modify values.
(#10850)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: New to php

Post by Kieran Huggins »

The slash is added due to something called "escaping" - the server you're on seems to be a little whacked, since this hasn't been an issue in quite some time. (since PHP 4.3 I think?)

The setting that's causing this is magic_quotes_gpc and PHP6 will be removing it altogether.

I'd strongly recommend you just shut it off. In your .htaccess file, add the line:

Code: Select all

php_flag magic_quotes_gpc off
and be done with it!
Post Reply