ffgghh Posted October 17, 2006 Report Share Posted October 17, 2006 Lūdzu palīdziet: Kā vis vienkāršāk teksta rindā aizvietot visus latviešu mīkstos burtus ar analogiem bez garumzīmēm, aizvietot atstarpes ar _, un vispār atļaut rindā tikai burtus??? $topiks =preg_replace('@[^\w\-_]@i', '_', $_POST['topiks']); -nomaina atstarpes un likvidē lat burtus.. HELP Link to comment Share on other sites More sharing options...
andrisp Posted October 17, 2006 Report Share Posted October 17, 2006 (edited) Man šeit ir viena nepārāk smuka fja, daudz regexpu: function strip_lv_nonalphanum($str) { $ko = array('/Ā/','/Č/','/Ē/','/Ģ/','/Ī/','/Ķ/', '/Ļ/','/Ņ/','/Ō/','/Š/','/Ū/','/Ž/', '/ā/','/č/','/ē/','/ģ/','/ī/','/ķ/', '/ļ/','/ņ/','/ō/','/š/','/ū/','/ž/'); $ar = array('A','C','E','G','I','K', 'L','N','O','S','U','Z', 'a','c','e','g','i','k', 'l','n','o','s','u','z'); $str = preg_replace($ko, $ar, $str); $str = preg_replace('/[^0-9a-z]/im', '_', $str); $str = preg_replace('/__+/im', '_', $str); $str = preg_replace('/_$/im', '', $str); $str = preg_replace('/^_/im', '', $str); return $str; } Edited October 17, 2006 by andrisp Link to comment Share on other sites More sharing options...
ffgghh Posted October 17, 2006 Author Report Share Posted October 17, 2006 PALDIES Link to comment Share on other sites More sharing options...
bubu Posted October 17, 2006 Report Share Posted October 17, 2006 andrisp, wtf? Šaujam pa zvirbuļiem ar lielgabalu? Kas vainas prastam str_replace("Ā"=>"A", ...) ? Link to comment Share on other sites More sharing options...
andrisp Posted October 17, 2006 Report Share Posted October 17, 2006 Ja godīgi, tad nebiju pamanījis, ka str_replace atbalsta masīvus :]. My bad. Link to comment Share on other sites More sharing options...
Recommended Posts