czechmate1976
asked on
Text messed up when returned from DB
When I submit text with apostrophies and speech marks in the text area.. when the text returns from the db totally messed up.
the submitted text is dealt as follows:
$content = htmlentities(mysql_prep($_ POST['cont ent']));
where mysql_prep is a function => below
the returned text is displayed the following way:
strip_tags(nl2br($sel_page ['content' ]),"<b><br ><p><a>");
the database field is set to text, utf8-general-ci
Will be very greatful if someone help me sort out this problem - I can't even think straight after a long weekend working ... Thanks a lot for all your tips
the submitted text is dealt as follows:
$content = htmlentities(mysql_prep($_
where mysql_prep is a function => below
the returned text is displayed the following way:
strip_tags(nl2br($sel_page
the database field is set to text, utf8-general-ci
Will be very greatful if someone help me sort out this problem - I can't even think straight after a long weekend working ... Thanks a lot for all your tips
function mysql_prep( $value ) { //parameter passed by the function caller - variable from a form
$magic_quotes_active = get_magic_quotes_gpc(); // this function has been deprecated in PHP 5.3.0 and removed from PHP6.0.0
$new_enough_php = function_exists( "mysql_real_escape_string"); // Tests if a function in brackets exists (returns TRUE or FALSE; it is to find out if PHP version is higher than v4.3
if( $new_enough_php ) { // PHP is of v4.3.0 or higher
// undo any magic quote effects so mysql real_escape_string function can do it
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
$value = mysql_real_escape_string( $value );
} else { // PHP versions older than v4.3.0
//if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = stripslashes( $value ); }
// if magic quotes are active, then the slashes already exists
}
return $value;
}
Show us some input and the output, please.
ASKER
ok, here is a sample... thanks a lot - Not sure if it has much to do with that - but the text is copied from a website with these speechmarks etc.
ENTERED TEXT:
The requirements for a mobile phone or 3G card are very important for the dayto-day communication for Agip KCO , FGE are able to provide a connection and hardware on the same day or within 2 days which is really good service
RETURNED TEXT:
âýýThe requirements for a mobile phone or 3G card are very important for the dayâýýto-day communication for Agip KCO , FGE are able to provide a connection and hardware on the same day or within 2 days which is really good serviceâýý
ENTERED TEXT:
The requirements for a mobile phone or 3G card are very important for the dayto-day communication for Agip KCO , FGE are able to provide a connection and hardware on the same day or within 2 days which is really good service
RETURNED TEXT:
âýýThe requirements for a mobile phone or 3G card are very important for the dayâýýto-day communication for Agip KCO , FGE are able to provide a connection and hardware on the same day or within 2 days which is really good serviceâýý
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Will check this out. thanks a lot!!1 Will let you guys know what I get from it, well after a bit of sleep :-)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you guys