This article mainly introduced the Joomla framework implementation of string interception method, involving PHP string and regular operation related skills, the need for friends can refer to the following
This paper describes the method of the Joomla framework to implement string interception. Share to everyone for your reference, as follows:
When using Joomla for development, we need to use foreign resources, some modules, components, plug-ins and the like, but we will find that in the string this method needs to be modified. Because PHP's substr method is only valid for non-Chinese strings, it's easy to use another easy way to mb_substr, so you can easily solve the problem of intercepting characters.
At the same time, if the need for Chinese, English, mixed three ways (except punctuation) to intercept the string, then the regular expression comes in handy, attached source code, for reference only.
/* Truncate string method *///$str string//$number for maximum length function cutstrtitle ($str, $number) { $str = strip_tags ($STR); $en =preg_match ('/^[a-za-z]/', $str);//matches the English alphabet $cn =preg_match_all ("/([\x{4e00}-\x{9fa5}]) {1}/u", $str, $ARRC); /Match Kanji, number of statistics, return to $ARRC if (Mb_strlen ($str, ' UTF8 ') <= $number) {//' UTF8 ' with the format of the string to adjust the return $str; } else{ if ($en) { if ($CN) { //in English mixed case return mb_substr ($str, 0, $number +2, ' utf-8 '). ' ...'; } else{ //Full English case return mb_substr ($str, 0, $number +4, ' utf-8 '). ' ...'; } } else { //For all Chinese cases return mb_substr ($str, 0, $number, ' utf-8 '). ' ...'; } }}
More readers interested in the content of PHP framework can view the topic: "PHP Excellent Development Framework Summary", "thinkphp Introductory Tutorial", "CodeIgniter Introductory Tutorial", "CI (codeigniter) Framework Advanced Tutorial", "Zend Framework Framework Primer Tutorial, Basic tutorial for getting started with Smarty Templates and PHP template technology summary.