UnitedForums - UK Web Hosting Forum UnitedHosting Community Hosting Forums
Network and Server StatusCustomer SupportUK Web Hosting
UnitedHostingUnitedHosting Sitemap UK Hosting ForumUK Web HostingWeb Hosting ForumsUK Reseller HostingWeb Host CommunityUK Managed Dedicated ServersHosting Help and SupportUK Domain Name Registration

Go Back   UnitedForums.co.uk > UnitedHosting Community > Website Development & Scripting

Reply
 
Thread Tools Rate Thread Display Modes
Old 19th July 2003, 06:09 PM   #1 (permalink)
SFADuncan
Registered User
 
Join Date: Jul 2003
Posts: 156
Trimming Strings etc

Beginning to tidy up some of my PHP and decided to start using AddSlashes, StripSlashes and Trim etc on certain strings for a very simple comment and feedback system I've written. But I have found that for some reason I don't need them - it seems the processes are already happening. Is this the way MySQL is already set up or something?

This is a problem, because on my main feedback form I want carriage returns to be acknowledge when returning them - which they are in the MySQL database, but not when returning the string to my web page.

Simon
SFADuncan is offline   Reply With Quote
Old 19th July 2003, 07:32 PM   #2 (permalink)
UH-Matt
Administrator
 
UH-Matt's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 8,135
This MIGHT be because PHP is compiled with "--enable-magic-quotes".

I believe you can turn off magic-quotes in your .htaccess file.

I am not a scripter so could be wrong
__________________
.
Matt
UnitedHosting Staff

For official support please use our helpdesk at UnitedSupport.co.uk

UnitedHosting proudly hosting more than 20,000 sites since 1998.
UH-Matt is offline   Reply With Quote
Old 20th July 2003, 08:47 AM   #3 (permalink)
Bman
Registered User
 
Join Date: May 2003
Posts: 22
Yes, Matt's right. Magic quotes are probably responsible for the behavior you're seeing with slashes. From the documentation:

Quote:
magic_quotes_gpc boolean

Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically.
The carriage returns are another matter, though. If they're in your database but not showing up on your page, have you made sure that you're converting them to HTML before displaying? You need a <br /> tag to display a newline, and there is no automatic conversion for that. Magic quotes only handles the quotes and slashes, and only works on data coming in, not going out.

You can call nl2br() to take care of newline->br tag conversion.
Bman is offline   Reply With Quote
Old 20th July 2003, 01:19 PM   #4 (permalink)
Euge
Registered User
 
Euge's Avatar
 
Join Date: Feb 2003
Location: Lost in confusion
Posts: 700
Here are some functions I use to ensure my addslashes and stripslashes always work based on the apache configuration. This makes your code much more portable.
PHP Code:
/**
* Used to return escaped text for a Get/Post/Cookie variable
* based on the php modules configuration
*/
function getGpcEscaped($x)
{
        return 
get_cfg_var(magic_quotes_gpc) ? $x addslashes($x) ;
}

/**
* Used to return unescaped text for a Get/Post/Cookie variable
* based on the php modules configuration
*/
function getGpcUnescaped($x)
{
        return 
get_cfg_var(magic_quotes_gpc) ? stripslashes($x) : $x ;

Euge is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 02:17 PM.

UK Web Hosting  |  UK Reseller Hosting  |  UK Dedicated Servers UnitedHosting  |  UnitedSupport  |  UnitedForums  |  SEO by vBSEO 3.0.0
Copyright © 1998-2008 United Communications Limited. All Rights Reserved. Registered in England and Wales 3651923 - VAT Reg No. 737662309