Jump to content

[SOLVED] replacing characters in a string


nbarone

Recommended Posts

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

 

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?

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.