PHP removes all spaces in the string and adds '% ' to each character before and after
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 10 three '; Echo strlen ($STR), '--strlen ', '
'; Echo mb_strlen ($str, ' utf-8 '), '--mb_strlen ', '
'; $arrstr = Str_split ($str); $arrstr = Str_split_unicode ($STR);//Meet Requirements $temp= "; foreach ($arrstr as $val) {$temp. = Trim ($ val);} echo $temp, '
';//Meet the requirements, remove the space after the string $arrstr = Str_split_unicode ($temp);//Meet the requirements $temp= '% '; foreach ($arrstr as $val) {$temp. = $val. '% ';} echo $temp, '
';//Meet the requirements, plus '% ' after the string echo Mb_strlen ($temp), '
'; Echo mb_strlen ($temp, ' utf-8 ');//Meet the requirements
The following Java code is used to implement
/** * */package cn.com.songjy.demo;/** * @author Songjianyong * */public class Likesqlcond Itiondemo {public static void main (string[] args) {System.out.println (getlikesqlcondition ("AA a D"));//output is:%a%a%a %d%}public static string Getlikesqlcondition (string condition) {if (Condition==null | | Condition.trim (). Length () ==0) return null;condition = Trim (condition),//Remove space 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
When querying for a like statement