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