Jump to content

removing special characters


ibinod

Recommended Posts

so what characters do you want to keep?

 

a-z, 0-9, !@#$%^&*() ;'.,[]{}":><|\~`

 

? a-z A-Z 0-9 all those symbols.. they are usually in succession, find out what their ascii values are and loop thru the text and remove anything thats not between those.. if you don't understand what I mean I'll help you out some more

Hello RussellReal,

 

actually i m making a script to get news content from yahoo rss and along with it i am getting characters like those �♪♫ and making XHTML invalid,

so what's the best way to remove those and similar chars

 

and how do i loop through text to remove those,

 

thanx

 

//i have some text in the database like this

$string = "  �Public Enemy Number One� has long interested people who have then journeyed to visit his last resting place;

♪♫ Zac Efron & Jessica Alba WIN '07 Teen Choice Hottie Award";

 

// i have this function to remove un necessory tags (actually those are for urls)

function sef_rep($name)

{

$name = html_entity_decode(strtolower($name));

 

$remove = array("/", "'", "`", "!", "(", ")", ".", "@", "+", " ", "_", "<", ">", "?", ":", ";", "&", "#", ",");

$result_str = str_replace($remove, '-', $name);

return $result_str;

}

 

//so when i echo this those special characters haven't gone

echo sef_rep($string);

 

 

 

 

so pls post me a solution to remove special chars like �

<?php
function sef_rep($name) {
$name = html_entity_decode(strtolower($name));
$r = range(33,126);
$remove = array("/", "'", "`", "!", "(", ")", ".", "@", "+", " ", "_", "<", ">", "?", ":", ";", "&", "#", ",");
$name = str_replace($remove, '-', $name);
$l = strlen($name);
for ($i = 0; $i < $l; $i++) {
	$c = ord(substr($name,$i,0));
	if (!in_array($c,$r)) {
		$name = substr($name,0,$i - 1).substr($name,$i + 1,$l - ($i + 1));
		$i--;
	}
}
return $name;
}
?>

try that

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.