laravelÔõô½ØÈ¡×Ö·û
laravelÊÇÒ»¸öÊ¢ÐеÄphp¿ò¼Ü£¬ÌṩÁË´ó×ڵĹ¦Ð§ºÍ¹¤¾ßÀ´¿ìËÙ¹¹½¨webÓ¦ÓóÌÐò¡£ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃǾ³£ÐèÒª¶Ô×Ö·û´®¾ÙÐд¦Àí£¬ÀýÈç½ØÈ¡×Ö·û¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlaravelÖнØÈ¡×Ö·û¡£
Ò»¡¢Ê¹ÓÃPHPÄÚÖú¯Êý½ØÈ¡×Ö·û
ÔÚLaravelÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃPHPÄÚÖú¯ÊýÀ´½ØÈ¡×Ö·û¡£PHPÌṩÁËÈý¸öº¯ÊýÀ´½ØÈ¡×Ö·û´®£ºsubstr()¡¢mb_substr()ºÍmb_strcut()¡£
substrº¯Êý
substrº¯ÊýÊÇPHPÄÚÖú¯ÊýÖ®Ò»£¬ÓÃÀ´½ØÈ¡×Ö·û´®µÄÒ»²¿·Ö¡£¸Ãº¯ÊýÓÐÈý¸ö²ÎÊý£º×Ö·û´®¡¢ÆðʼλÖúͳ¤¶È¡£
ʾÀý´úÂ룺
$str = "Hello world"; $substr = substr($str, 0, 5); echo $substr; //Êä³ö Hello
µÇ¼ºó¸´ÖÆ
ÔÚʾÀý´úÂëÖУ¬$strÊÇÒª½ØÈ¡µÄ×Ö·û´®£¬0ÊÇÆðʼλÖã¬5ÊÇÒª½ØÈ¡µÄ³¤¶È¡£substrº¯Êý·µ»Ø½ØÈ¡µÄ×Ö·û´®¡£
mb_substrº¯Êý
mb_substrº¯ÊýÊÇÓÃÓÚ¶à×Ö½Ú×Ö·û¼¯µÄ×Ö·û´®½ØÈ¡º¯Êý¡£ËüµÄ²ÎÊýºÍÓ÷¨Óësubstrº¯ÊýÏàͬ£¬¿ÉÊÇËü¿ÉÒÔ´¦ÀíÖÐÎĵȶà×Ö½Ú×Ö·û¡£ÐèҪעÖصÄÊÇ£¬Ê¹ÓÃmb_substrº¯ÊýÐèÒªÔÚphp.iniÖпªÆômbstringÀ©Õ¹¡£
ʾÀý´úÂ룺
$str = "ÄãºÃ£¬ÌìÏÂ"; $substr = mb_substr($str, 0, 2, 'utf-8'); echo $substr; //Êä³ö ÄãºÃ
µÇ¼ºó¸´ÖÆ
ÔÚʾÀý´úÂëÖУ¬$strÊÇÒª½ØÈ¡µÄ×Ö·û´®£¬0ÊÇÆðʼλÖã¬2ÊÇÒª½ØÈ¡µÄ³¤¶È£¬’utf-8’ÌåÏÖ×Ö·û´®±àÂë¡£mb_substrº¯Êý·µ»Ø½ØÈ¡µÄ×Ö·û´®¡£
mb_strcutº¯Êý
mb_strcutº¯ÊýÒ²ÊÇÓÃÓÚ¶à×Ö½Ú×Ö·û¼¯µÄ×Ö·û´®½ØÈ¡º¯Êý¡£ËüµÄ²ÎÊýºÍÓ÷¨Óëmb_substrº¯ÊýÏàͬ£¬¿ÉÊÇËü¿ÉÒÔ°ü¹Ü½ØȡЧ¹û²»º¬Óаë¸ö×Ö·û¡£
ʾÀý´úÂ룺
$str = "ÄãºÃ£¬ÌìÏÂ"; $substr = mb_strcut($str, 0, 2, 'utf-8'); echo $substr; //Êä³ö ÄãºÃ
µÇ¼ºó¸´ÖÆ
¶þ¡¢Ê¹ÓÃLaravelµÄ×Ö·û´®²Ù×÷º¯Êý½ØÈ¡×Ö·û
LaravelÌṩÁËÐí¶à×Ö·û´®²Ù×÷º¯Êý£¬¿ÉÒÔ¼ò»¯ÎÒÃǽØÈ¡×Ö·û´®µÄ²Ù×÷¡£
Str::substrº¯Êý
Str::substrº¯ÊýÊÇLaravelµÄ×Ö·û´®½ØÈ¡º¯Êý¡£¸Ãº¯ÊýµÄ²ÎÊýºÍsubstrº¯ÊýµÄ²ÎÊýÏàͬ¡£
ʾÀý´úÂ룺
use Illuminate\Support\Str; $str = "Hello world"; $substr = Str::substr($str, 0, 5); echo $substr; //Êä³ö Hello
µÇ¼ºó¸´ÖÆ
ÔÚʾÀý´úÂëÖУ¬ÎÒÃÇÐèÒªÏÈÒýÈëStrÀ࣬Ȼºó¾Í¿ÉÒÔʹÓÃStr::substrº¯Êý½ØÈ¡×Ö·û´®¡£
Str::limitº¯Êý
Str::limitº¯ÊýÊÇLaravelµÄÏÞÖÆ×Ö·û´®³¤¶Èº¯Êý¡£¸Ãº¯ÊýÓÐÈý¸ö²ÎÊý£º×Ö·û´®¡¢³¤¶ÈºÍ×îºó×Ö·û¡£
ʾÀý´úÂ룺
use Illuminate\Support\Str; $str = "Hello world"; $limitStr = Str::limit($str, 5, '...'); echo $limitStr; //Êä³ö Hello...
µÇ¼ºó¸´ÖÆ
ÔÚʾÀý´úÂëÖУ¬$strÊÇÒª½ØÈ¡µÄ×Ö·û´®£¬5ÊÇÒª½ØÈ¡µÄ³¤¶È£¬’…’ÊÇ×îºó×Ö·û¡£Str::limitº¯Êý·µ»Ø½ØÈ¡µÄ×Ö·û´®¡£
Str::wordsº¯Êý
Str::wordsº¯ÊýÊÇLaravelµÄÏÞÖƵ¥´ÊÊýÄ¿º¯Êý¡£¸Ãº¯ÊýÓÐÈý¸ö²ÎÊý£º×Ö·û´®¡¢µ¥´ÊÊýÄ¿ºÍ×îºó×Ö·û¡£
ʾÀý´úÂ룺
use Illuminate\Support\Str; $str = "Hello world, how are you doing today?"; $wordsStr = Str::words($str, 3, '...'); echo $wordsStr; //Êä³ö Hello world, how...
µÇ¼ºó¸´ÖÆ
ÔÚʾÀý´úÂëÖУ¬$strÊÇÒª½ØÈ¡µÄ×Ö·û´®£¬3ÊÇÒª½ØÈ¡µÄµ¥´ÊÊýÄ¿£¬’…’ÊÇ×îºó×Ö·û¡£Str::wordsº¯Êý·µ»Ø½ØÈ¡µÄ×Ö·û´®¡£
×ܽá
±¾ÎÄÏÈÈÝÁËÔÚLaravelÖнØÈ¡×Ö·ûµÄÁ½ÖÖÒªÁ죺ʹÓÃPHPÄÚÖú¯ÊýºÍʹÓÃLaravelµÄ×Ö·û´®²Ù×÷º¯Êý¡£Ê¹ÓÃPHPÄÚÖú¯Êý¿ÉÒÔ´¦Àí¶à×Ö½Ú×Ö·û£¬µ«ÐèÒªÔÚphp.iniÖпªÆômbstringÀ©Õ¹£»Ê¹ÓÃLaravelµÄ×Ö·û´®²Ù×÷º¯Êý¿ÉÒÔ¼ò»¯¿ª·¢£¬²¢¿ÉÒÔÏÞÖÆ×Ö·û´®³¤¶È»òµ¥´ÊÊýÄ¿¡£Æ¾Ö¤ÏÖʵÐèÇóÑ¡Ôñ²î±ðµÄÒªÁì¼´¿É¡£
ÒÔÉϾÍÊÇlaravelÔõô½ØÈ¡×Ö·ûµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡