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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

//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 �

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.