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 Quote 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)?> Quote 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 Quote 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; } ?> Quote 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() Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.