Page 1 of 1

Replacing single quote does not work

Posted: Thu Jan 20, 2011 2:20 am
by nelliza111
I am trying to do the seemingly simple thing - replace all single quotes in html output.

Code: Select all

ereg_replace ("'", "'", $text);
It does not replace anything.

The code line is within function where other lines work perfectly.

Code: Select all

function convert_quotes ($text) {
	$text = ereg_replace ('"', """, $text);
	$text = ereg_replace ("'", "", $text);	
	$text = ereg_replace ('“', "“", $text);
	$text = ereg_replace ('”', "”", $text);
	$text = ereg_replace ('‘', "‘", $text);
	$text = ereg_replace ('’', "’", $text);
	$text = ereg_replace ('«', "«", $text);
	$text = ereg_replace ('»', "»", $text);
	
	return $text;
}
And yes, someone tried to run it on their server and it all works including single quote. Not on mine.

I tried escaping single quote, used other similar functions (preg_replace, str_replace) - nope.
Tried htmlspecialchars - nope.

I did look at html source. Did read FAQs and manuals. I tried hard to google. I posted to other help forum. With no luck so far.

I have standard CentOS build, did not edit php.ini. Here is php_ini page http://maidan.org.ua/test.php

What would be wrong there?

Any help would ne much appreciated.

Re: Replacing single quote does not work

Posted: Thu Jan 20, 2011 11:11 am
by Jonah Bron
First, why do you need to convert apostrophes? You can convert all HTML reserved characters with htmlentities().

http://php.net/htmlentities

Also, all ereg(i)_* functions are depreciated, use str_replace() instead.

http://php.net/str-replace