Introduction to how to intercept string implementations in the Joomla framework

Source: Internet
Author: User
Tags php framework php template codeigniter zend framework
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.