rebuilder Posted September 29, 2010 Report Share Posted September 29, 2010 Interesē vai ir tāda funkcija, kas no vārda aizvāc visas garumzīmes, mīkstinājumus utt un atstarpju vietā ieliek "_" ? Quote Link to comment Share on other sites More sharing options...
Леший Posted September 29, 2010 Report Share Posted September 29, 2010 http://lv.php.net/manual/en/function.str-replace.php Quote Link to comment Share on other sites More sharing options...
codez Posted September 29, 2010 Report Share Posted September 29, 2010 $s='Tavs strings ar garumzīmēm un atstarpēm'; $s=preg_replace("/[^a-zA-Z0-9 ]/", "", $s); //aizvāc visu, kas nav A-Z,a-z,0-9 un atstarpe. $s=preg_replace('/[\s]+/', '_', $s); //aizvieto atstarpes ar _ Quote Link to comment Share on other sites More sharing options...
rebuilder Posted September 29, 2010 Author Report Share Posted September 29, 2010 Skaidrs, biju iedomājies, ka ir kāds cits veids, paldies par informāciju :) Quote Link to comment Share on other sites More sharing options...
briedis Posted September 29, 2010 Report Share Posted September 29, 2010 Man liekas, ka viņš meklē priekš seo. OP, pameklē šeit forumā, ir topiks Noderīgas Funkcijas piepinnots. Tur ir atrodams tas, ko meklē. Quote Link to comment Share on other sites More sharing options...
sheps Posted September 29, 2010 Report Share Posted September 29, 2010 (edited) $s=preg_replace("/[^a-zA-Z0-9 ]/", "", $s); //aizvāc visu, kas nav A-Z,a-z,0-9 un atstarpe. šis aizvāks garos un mīkstos patskaņus, bet man liekas viņš domāja to aizvietots ar parastiem.. nāksies vien ar roku sarakstiik kurus simbolus aizvietot.. ā ar a.. bet funkcija jau der :D Edited September 29, 2010 by sheps Quote Link to comment Share on other sites More sharing options...
briedis Posted September 29, 2010 Report Share Posted September 29, 2010 ok, iebarosim ar karotīti: /** * Funkcija pārkonverte virkni uz SEO virkni (slug) * @param string $str Konvertējamā virkne * @param string $separator Tukšumusimbolu aizstājējs * @return string Konvertētā virkne */ function getSeo($str, $separator = '-'){ $str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str); $str = trim(preg_replace('/[^ A-Za-z0-9_-]/', ' ', $str)); return preg_replace('/[ -]+/', $separator, $str); } Quote Link to comment Share on other sites More sharing options...
rebuilder Posted October 1, 2010 Author Report Share Posted October 1, 2010 briedis Paldies, bet sen jau visu atrisināju ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.