Re: Function suggestion

From: Date: Tue, 10 Apr 2001 19:43:08 +0000
Subject: Re: Function suggestion
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-51395@lists.php.net to get a copy of this message
Using str_replace() would speed this function up by an order of magnitude. On Tue, 10 Apr 2001, Lindsey Simon wrote: > I'm not positive I'm mailing to the right list, but I have a function that might be > useful > to others. I often use php to retrieve a name from a database and then let a user upload a > file and I name that file by as $user.mp3(in this case). I need to convert all of the > international characters to a standard character for this since different OS's send > requests for filenames with non-standard standards... > > so here goes: > > function intl2plain ($thing) { > $thing = preg_replace("/xE0/", "a", $thing); > $thing = preg_replace("/xE8/", "e", $thing); > $thing = preg_replace("/xEC/", "i", $thing); > $thing = preg_replace("/xF2/", "o", $thing); > $thing = preg_replace("/xF9/", "u", $thing); > > $thing = preg_replace("/\xC0/", "A", $thing); > $thing = preg_replace("/\xC8/", "E", $thing); > $thing = preg_replace("/\xCC/", "I", $thing); > $thing = preg_replace("/\xD2/", "O", $thing); > $thing = preg_replace("/\xD9/", "U", $thing); > > $thing = preg_replace("/\xE1/", "a", $thing); > $thing = preg_replace("/\xE9/", "e", $thing); > $thing = preg_replace("/\xED/", "i", $thing); > $thing = preg_replace("/\xF3/", "o", $thing); > $thing = preg_replace("/\xFA/", "u", $thing); > $thing = preg_replace("/\xFD/", "y", $thing); > > $thing = preg_replace("/\xC1/", "A", $thing); > $thing = preg_replace("/\xC9/", "E", $thing); > $thing = preg_replace("/\xCD/", "I", $thing); > $thing = preg_replace("/\xD3/", "O", $thing); > $thing = preg_replace("/\xDA/", "U", $thing); > $thing = preg_replace("/\xDD/", "Y", $thing); > > $thing = preg_replace("/\xE2/", "a", $thing); > $thing = preg_replace("/\xEA/", "e", $thing); > $thing = preg_replace("/\xEE/", "i", $thing); > $thing = preg_replace("/\xF4/", "o", $thing); > $thing = preg_replace("/\xFB/", "u", $thing); > > $thing = preg_replace("/\xC2/", "A", $thing); > $thing = preg_replace("/\xCA/", "E", $thing); > $thing = preg_replace("/\xCE/", "I", $thing); > $thing = preg_replace("/\xD4/", "O", $thing); > $thing = preg_replace("/\xDB/", "U", $thing); > > $thing = preg_replace("/\xE3/", "a", $thing); > $thing = preg_replace("/\xF1/", "n", $thing); > $thing = preg_replace("/\xF5/", "o", $thing); > > $thing = preg_replace("/\xC3/", "A", $thing); > $thing = preg_replace("/\xD1/", "N", $thing); > $thing = preg_replace("/\xD5/", "O", $thing); > > $thing = preg_replace("/\xE4/", "a", $thing); > $thing = preg_replace("/\xEB/", "e", $thing); > $thing = preg_replace("/\xEF/", "i", $thing); > $thing = preg_replace("/\xF6/", "o", $thing); > $thing = preg_replace("/\xFC/", "u", $thing); > $thing = preg_replace("/\xFF/", "y", $thing); > > $thing = preg_replace("/\xC4/", "A", $thing); > $thing = preg_replace("/\xCB/", "E", $thing); > $thing = preg_replace("/\xCF/", "I", $thing); > $thing = preg_replace("/\xD6/", "O", $thing); > $thing = preg_replace("/\xDC/", "U", $thing); > $thing = preg_replace("/\x9f/", "Y", $thing); > > $thing = preg_replace("/\xE7/", "c", $thing); > $thing = preg_replace("/\xC7/", "C", $thing); > > return $thing; > } > > Maybe it's useful for others, it's along the lines of htmlspecialchars(); etc... > > -lindsey > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.dev (#51395) next »