madcrazy1 Posted October 11, 2007 Share Posted October 11, 2007 hi, how can i replace the ampersand with & before it gets stored in the database. i have an existing function the actually strips the script tags, can something be added to this bit of code to get this accomplished? <?php function escape_string($string) { return get_magic_quotes_gpc()?mysql_real_escape_string(stripslashes($string)):mysql_real_escape_string($string); } function html2txt($document){ $search = array('@<script[^>]*?>.*?</script>@si'); $text = preg_replace($search, '', $document); return $text; } ?> thank you Link to comment https://forums.phpfreaks.com/topic/72727-solved-replace-ampersand-before-gets-to-db/ Share on other sites More sharing options...
darkfreaks Posted October 11, 2007 Share Posted October 11, 2007 <?php $string=str_replace('&','&',$string)?> Link to comment https://forums.phpfreaks.com/topic/72727-solved-replace-ampersand-before-gets-to-db/#findComment-366787 Share on other sites More sharing options...
madcrazy1 Posted October 12, 2007 Author Share Posted October 12, 2007 novice here-not sure how thats supposed to fit in with the code above. thx Link to comment https://forums.phpfreaks.com/topic/72727-solved-replace-ampersand-before-gets-to-db/#findComment-367563 Share on other sites More sharing options...
darkfreaks Posted October 12, 2007 Share Posted October 12, 2007 <?php function escape_string($string) { return get_magic_quotes_gpc() ?mysql_real_escape_string(stripslashes($string)):mysql_real_escape_string($string) :str_replace('&','&',$string); } function html2txt($document){ $search = array('@<script[^>]*?>.*?</script>@si'); $text = preg_replace($search, '', $document); return $text; } ?> Link to comment https://forums.phpfreaks.com/topic/72727-solved-replace-ampersand-before-gets-to-db/#findComment-367572 Share on other sites More sharing options...
hvle Posted October 12, 2007 Share Posted October 12, 2007 You want to look at the function htmlentities() Link to comment https://forums.phpfreaks.com/topic/72727-solved-replace-ampersand-before-gets-to-db/#findComment-367606 Share on other sites More sharing options...
madcrazy1 Posted October 15, 2007 Author Share Posted October 15, 2007 thank you Link to comment https://forums.phpfreaks.com/topic/72727-solved-replace-ampersand-before-gets-to-db/#findComment-369753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.