nbarone Posted July 2, 2009 Share Posted July 2, 2009 I have built a CMS to change content on a webpage, however, 90% of the content is givin to me in MS .docx format, and the people who write the content use lots of special characters. Here is what I have to switch them over: $content = $_REQUEST['pg_u_content']; $content = ereg_replace("’","'",$content); $content = ereg_replace("”","\"",$content); $content = ereg_replace("“","\"",$content); $content = ereg_replace("–","-",$content); $content = ereg_replace("é","e",$content); is there an easier way? It seems that their would be... Link to comment https://forums.phpfreaks.com/topic/164523-solved-replacing-characters-in-a-string/ Share on other sites More sharing options...
947740 Posted July 2, 2009 Share Posted July 2, 2009 http://us2.php.net/str_replace Link to comment https://forums.phpfreaks.com/topic/164523-solved-replacing-characters-in-a-string/#findComment-867769 Share on other sites More sharing options...
nbarone Posted July 2, 2009 Author Share Posted July 2, 2009 http://us2.php.net/str_replace Thanks, this is what I have now: $content = $_REQUEST['pg_u_content']; $c_find = array("’","”","“","–","é"); $c_replace = array("'","\"","\"","-","é"); $content = str_replace($c_find,$c_replace,$content); However, is this the most efficient way to handle this? Link to comment https://forums.phpfreaks.com/topic/164523-solved-replacing-characters-in-a-string/#findComment-867772 Share on other sites More sharing options...
947740 Posted July 2, 2009 Share Posted July 2, 2009 You did not ask for a more efficient way, but I would imagine it would be once you get a lot of characters. Having to run one function several times compared to running one function once... As to your initial question, it would be easier (to me, at least) just to have arrays, because you just tack on characters to the end of each array, instead of creating a whole new line of code. Link to comment https://forums.phpfreaks.com/topic/164523-solved-replacing-characters-in-a-string/#findComment-867776 Share on other sites More sharing options...
Mark Baker Posted July 2, 2009 Share Posted July 2, 2009 Or it might be better to use htmlentities() or htmlspecialchars() Link to comment https://forums.phpfreaks.com/topic/164523-solved-replacing-characters-in-a-string/#findComment-867778 Share on other sites More sharing options...
nbarone Posted July 2, 2009 Author Share Posted July 2, 2009 You did not ask for a more efficient way, but I would imagine it would be once you get a lot of characters. Having to run one function several times compared to running one function once... As to your initial question, it would be easier (to me, at least) just to have arrays, because you just tack on characters to the end of each array, instead of creating a whole new line of code. Thank you, by "most efficient" way I meant was the something similar to htmlentities that converted special characters to HTML-readable characters. This will work fine, since this CMS will only be used periodically. Thank you very much for the help. Link to comment https://forums.phpfreaks.com/topic/164523-solved-replacing-characters-in-a-string/#findComment-867779 Share on other sites More sharing options...
nbarone Posted July 2, 2009 Author Share Posted July 2, 2009 Or it might be better to use htmlentities() or htmlspecialchars() Thanks, but neither of those do what I am trying to accomplish. Link to comment https://forums.phpfreaks.com/topic/164523-solved-replacing-characters-in-a-string/#findComment-867783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.