Digital Point Forums
Moneygram

Go Back   Digital Point Forums > Design & Development > Programming > PHP
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Dec 26th 2007, 10:24 am
baris22 baris22 is offline
Hand of A'dal
 
Join Date: Jan 2007
Location: UK
Posts: 410
baris22 is on a distinguished road
Is there an easy way to replace …ÂÃ... using str replace

Hello all,

I am looking for an easy way to replace all these none english characters using str replace.

At the moment i am using

php Code:
$to_replace = array("Ã","ƒ","â","¦","š");
Is there an easier way to do this instead of my way?

Thanks
__________________

Rapidme
-rapidshare software-
Reply With Quote
  #2  
Old Dec 26th 2007, 10:40 am
JungleBook JungleBook is offline
Banned
 
Join Date: Dec 2007
Posts: 371
JungleBook is an unknown quantity at this point
That's the same way I do it to, I would like to know a better way!
Reply With Quote
  #3  
Old Dec 26th 2007, 1:11 pm
azizny's Avatar
azizny azizny is offline
Starcaller
 
Join Date: Jul 2006
Location: USA
Posts: 2,607
azizny is a jewel in the roughazizny is a jewel in the roughazizny is a jewel in the roughazizny is a jewel in the rough
Use this function:

php Code:
function cleanname($thename){
$patternCounter=0;

/*
$patterns[$patternCounter] = '/[\x21-\x2d]/u'; // remove range of shifted characters on keyboard - !"#$%&'()*+,-
$patternCounter++;

$patterns[$patternCounter] = '/[\x5b-\x60]/u'; // remove range including brackets - []\^_`
$patternCounter++;
*/


$patterns[$patternCounter] = '/[\x7b-\xff]/u'; // remove all characters above the letter z.  This will eliminate some non-English language letters
$patternCounter++;

$replacement ="";

     return preg_replace($patterns, $replacement, $thename);
}

$new_name = cleanname($thename);
Peace,
__________________
Testing 1.. Testing 1..2.. Testing 1..2..3..
Reply With Quote
  #4  
Old Dec 26th 2007, 1:38 pm
baris22 baris22 is offline
Hand of A'dal
 
Join Date: Jan 2007
Location: UK
Posts: 410
baris22 is on a distinguished road
I could not make it work.

Quote:
Originally Posted by azizny View Post
Use this function:

php Code:
function cleanname($thename){
$patternCounter=0;

/*
$patterns[$patternCounter] = '/[\x21-\x2d]/u'; // remove range of shifted characters on keyboard - !"#$%&'()*+,-
$patternCounter++;

$patterns[$patternCounter] = '/[\x5b-\x60]/u'; // remove range including brackets - []\^_`
$patternCounter++;
*/


$patterns[$patternCounter] = '/[\x7b-\xff]/u'; // remove all characters above the letter z.  This will eliminate some non-English language letters
$patternCounter++;

$replacement ="";

     return preg_replace($patterns, $replacement, $thename);
}

$new_name = cleanname($thename);
Peace,
__________________

Rapidme
-rapidshare software-
Reply With Quote
  #5  
Old Dec 26th 2007, 10:08 pm
ImpulseHorizon ImpulseHorizon is offline
Grunt
 
Join Date: Dec 2007
Posts: 31
ImpulseHorizon is on a distinguished road
Thanks, I will try this. does anyone know why these characters show up in the first place?
Reply With Quote
  #6  
Old Dec 26th 2007, 10:37 pm
Dondon2d Dondon2d is offline
Starcaller
 
Join Date: Feb 2007
Location: Glast Heim
Posts: 2,873
Dondon2d is a splendid one to beholdDondon2d is a splendid one to beholdDondon2d is a splendid one to beholdDondon2d is a splendid one to beholdDondon2d is a splendid one to beholdDondon2d is a splendid one to beholdDondon2d is a splendid one to behold
Something to do with character set I think.
__________________
Reply With Quote
  #7  
Old Dec 27th 2007, 1:18 am
Kaizoku's Avatar
Kaizoku Kaizoku is offline
of the Nightfall
 
Join Date: Dec 2007
Posts: 1,040
Kaizoku will become famous soon enough
Convert it to ISO-8859-1

php Code:
$newText = iconv("UTF-8", "ISO-8859-1", "…ÂÃ");
Reply With Quote
  #8  
Old Nov 22nd 2008, 11:31 am
butterman butterman is offline
Peon
 
Join Date: Oct 2008
Posts: 20
butterman is on a distinguished road
<?
$find[] = '“'; // left side double smart quote
$find[] = '”'; // right side double smart quote
$find[] = '‘'; // left side single smart quote
$find[] = '’'; // right side single smart quote
$find[] = '…'; // elipsis
$find[] = '—'; // em dash
$find[] = '–'; // en dash

$replace[] = '"';
$replace[] = '"';
$replace[] = "'";
$replace[] = "'";
$replace[] = "...";
$replace[] = "-";
$replace[] = "-";

$text = str_replace($find, $replace, $text);
?>

lol, a bit old but how knows.. it still useful
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A little help about str replace turifungia PHP 2 Dec 8th 2007 1:50 pm
I need a Preg Replace algo to replace SRC links softgroups PHP 7 Oct 9th 2007 3:12 am
preg replace - replace links pairbrother PHP 3 Jun 18th 2007 2:23 am
I need a quick find/replace tool to replace adsense channels justsomepoordude Site & Server Administration 6 Aug 11th 2006 2:13 pm
str replace? Weirfire PHP 7 Sep 6th 2005 3:44 am


All times are GMT -8. The time now is 7:13 am.