yeahz Posted October 18, 2009 Report Share Posted October 18, 2009 -br-----b-notice--b----undefined-index---image-title-in--b-c--appserv-www-switch-mygallery-php--b--on-line--b-174--b--br----43- Kā lai panāk ka izveidojas šādi? br-b-notice-b-undefined-index-image-title-in-b-c-appserv-www-switch-mygallery-php-b-on-line-b-174-b-br-43 Tātad lai visi "-----" tiek aizvietoti ar vienu "-", un ja pirmais un pēdējais ir "-", tad tas tiek izdzēsts. Quote Link to comment Share on other sites More sharing options...
Klez Posted October 18, 2009 Report Share Posted October 18, 2009 kā tu tās strīpiņas ģenerē ? rādi kodu Quote Link to comment Share on other sites More sharing options...
yeahz Posted October 18, 2009 Author Report Share Posted October 18, 2009 function fixlink($title) { $title = strtolower($title); return preg_replace("/[^a-z0-9-]/", "-", iconv("UTF-8", "ISO-8859-1//TRANSLIT", $title)); } te būs sākuma teksts <br /> <b>Notice</b>: Undefined index: image_title in <b>C:\AppServ\www\switch\mygallery.php</b> on line <b>174</b><br />-43 Quote Link to comment Share on other sites More sharing options...
Klez Posted October 18, 2009 Report Share Posted October 18, 2009 varu ieteikt ar preg_replace aizstāt visus tukšumus kas ir lielāki par 1 space, ar vienu space. http://lv.php.net/manual/en/function.preg-replace.php Example #5 Strip whitespace Quote Link to comment Share on other sites More sharing options...
yeahz Posted October 18, 2009 Author Report Share Posted October 18, 2009 Bet kā lai to space nomaina pret "-"? šis ir space - /\s\s+/ kāds būs "-"? Quote Link to comment Share on other sites More sharing options...
waplet Posted October 18, 2009 Report Share Posted October 18, 2009 tā arī raksit - /--+/i kad es raksīju lai ņeņem php ekstencijs darīju šādi /php/i , i ķipa case insensitive, preg vispār grūti ir saprast Quote Link to comment Share on other sites More sharing options...
yeahz Posted October 18, 2009 Author Report Share Posted October 18, 2009 Sataisīju. function fixlink($title) { $title = strtolower($title); return preg_replace('/\W\W+/', '-', preg_replace("/[^a-z0-9-]/", "-", iconv("UTF-8", "ISO-8859-1//TRANSLIT", $title))); } Tātad visi, kas nebūs A-Z, a-z, 0-9 un kuri kopā būs vairāk kā 1, tiks aizvietots ar -. Quote Link to comment Share on other sites More sharing options...
marcis Posted October 18, 2009 Report Share Posted October 18, 2009 function fixlink($title){ $title = strtolower($title); return preg_replace(array( '/[^a-z0-9\-]/', '/\-+/', '/^-/', '/\-$/' ), array( '-', '-', '', '' ), iconv("UTF-8", "ISO-8859-1//TRANSLIT", $title)); } 1. Visu, kas nav mazie latīņu burti un cipari, aizvietojam ar dash 2. Vienu un vairāk dash'us aizvietojam ar vienu dash 3. Aizvācam dash, kas atrodas stringa sākumā 4. Aizvācam dash, kas atrodas stringa beigās 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.