ArnisR Posted July 22, 2010 Report Share Posted July 22, 2010 $sometext = "Šeit ir kaut kāds teksts"; Kā PHP mainīgo sometext pārvērst par šādu: $sometext = "seit-ir-kaut-kads-teksts"; Tātad, kā redzams, visas atstarpes aizvietojās ar "-", un latviešu burtiem tika noņemtas mīkstinājuma un garumzīmes, kā arī lieli burti pārtapa par maziem. Quote Link to comment Share on other sites More sharing options...
codez Posted July 22, 2010 Report Share Posted July 22, 2010 Internetā to meklē kā "slug". Es izmantoju šādu variantu. function toSlug($s){ if (function_exists('iconv')) { $s = @iconv('utf-8', 'us-ascii//TRANSLIT', $s); } $s = preg_replace("/[&<>]/", " ", $s); $s = preg_replace("/[^a-zA-Z0-9 -]/", "", $s); $s = preg_replace('/[\s]+/', '-', $s); $s = mb_strtolower($s); $s = trim($s, " \t. -"); return $s; } Quote Link to comment Share on other sites More sharing options...
marcis Posted July 22, 2010 Report Share Posted July 22, 2010 (edited) Noderīgo funkciju topika šī lieta tika pieminēta vairākas reizes, rekur 2 izceltās: http://php.lv/f/topic/15423-noderigas-funkcijas/page__p__118661#entry118661 - izskatās bišķ šačakarēta http://php.lv/f/topic/15423-noderigas-funkcijas/page__p__118666#entry118666 - ereg sucks P.S. +1 codez Edited July 22, 2010 by marcis 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.