Hi
I have a variable which contains this data :
$text =

This is the company’s profile info, Please see this. “This is special announcement,” I have this texts.

Now I want to remove the special characters from this variable. I want to remove ’ “ and some other non-standard characters.

I have tried this :

$text = str_replace( '’', "'" , $text );
$text = str_replace( '“', '"' , $text );

But still this is not working. Is there any builtin php function that can do this?
Help me on this.
Thank you

Well I can guarantee you haven't tried what you said because you'd get a bunch of errors. A) You're not calling a function, B) you have overlapping/unclosed quotes, C) because of A you have unnecessary commas.

Go look at http://www.php.net because I can also guarantee you haven't looked there yet.

You are almost right

I also tested this and working here.
But sorry for above details are not full details.

here is my code :

<?php

$data = "This is “test” this is normal text.";
print $data;
$data2 = str_replace('“','_',$data);
$data2 = str_replace('”','_',$data2);
print ' <br> ';
print $data2;

print '<hr>';

// Database connection
mysql_connect("localhost", "root", "test") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());

// getting menu list
$mainmenuquery = "SELECT * FROM datatable WHERE id=100";
$mainmenuresult = mysql_query($mainmenuquery) or die(mysql_error());

while($mainmenurow = mysql_fetch_array($mainmenuresult, MYSQL_ASSOC)) {
	//print $mainmenurow['bodytext'];
	$introtext = str_replace('”','_',$mainmenurow['bodytext']);
	$introtext = str_replace('“','_',$introtext);
	//$introtext = str_replace('test','_',$introtext); // This is to test that this is working or not.

	print ' <br> ';
	print $introtext;
	print '<hr>';
}

?>

The first code before <hr> tag is working and the str_replace is also working perfectly.

But when I fatch the same data from database and apply the str_replace command than it does not work. My "datatable" table contains the the same test as $data variable contains. But still not working.

use string functions for this purpose

My 2 cents, you can pass an array as the 1st and 2nd argument of str_replace function.

<?php
$search_array = array("”","“");
$replace_string = "_";
//query 
//while loop
$introtext = str_replace($search_array,$replace_string,$mainmenurow['bodytext']); 
//....
?>

This is not different from your piece of code. But, both of these should work!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.