PHP removes all spaces in the string and adds '%' before and after each character'

Source: Internet
Author: User
PHP removes all spaces in the string and adds '%' functionstr _ split_unicode ($ str, $ l = 0) before and after each character {if ($ l & gt; 0) {$ ret = array (); $ len = mb_strl PHP removes all spaces in the string and adds '%' before and after each character'
Function str_split_unicode ($ str, $ l = 0) {if ($ l> 0) {$ ret = array (); $ len = mb_strlen ($ str, "UTF-8 "); for ($ I = 0; $ I <$ len; $ I + = $ l) {$ ret [] = mb_substr ($ str, $ I, $ l, "UTF-8");} return $ ret;} return preg_split ("// u", $ str,-1, PREG_SPLIT_NO_EMPTY);} $ str = 'Z 13 '; echo strlen ($ str), '-- strlen ','
'; Echo mb_strlen ($ str, 'utf-8'),' -- mb_strlen ','
'; $ Arrstr = str_split ($ str); $ arrstr = str_split_unicode ($ str); // meets the requirements $ temp = ''; foreach ($ arrstr as $ val) {$ temp. = trim ($ val);} echo $ temp ,'
'; // Conform to the requirements. Remove the space string $ arrstr = str_split_unicode ($ temp); // conform to the requirements $ temp =' % '; foreach ($ arrstr as $ val) {$ temp. = $ val. '%';} echo $ temp ,'
'; // Meets the requirements, and the echo mb_strlen ($ temp) string after' % 'is added ),'
'; Echo mb_strlen ($ temp, 'utf-8'); // meets the requirements



The following is implemented using java code.
/*****/Package cn.com. songjy. demo;/*** @ author songjianyong **/public class LikeSqlConditionDemo {public static void main (String [] args) {System. out. println (getLikeSqlCondition ("aa a d"); // The output result is: % a % d %} public static String getLikeSqlCondition (String condition) {if (condition = null | condition. trim (). length () = 0) return null; condition = trim (condition); // remove spaces String [] str = condition. split (""); String temp = ""; for (String string: str) {temp + = string + "%";} return temp ;} public static String trim (String str) {String temp = ""; for (int I = 0; I
 
  


The

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.