PHP去除字符串中的所有空格及在每个字符前后加下‘%’
PHP去除字符串中的所有空格及在每个字符前后加上‘%’
function str_split_unicode($str, $l = 0) { if ($l > 0) { $ret = array(); $len = mb_strlen($str, "UTF-8"); for ($i = 0; $i '; echo mb_strlen($str, 'utf-8'),'--mb_strlen','<br>'; $arrstr = str_split($str); $arrstr = str_split_unicode($str);//符合要求 $temp=''; foreach ($arrstr as $val){ $temp.= trim($val); } echo $temp, '<br>';//符合要求,去除空格后的字符串 $arrstr = str_split_unicode($temp);//符合要求 $temp='%'; foreach ($arrstr as $val){ $temp.=$val.'%'; } echo $temp,'<br>';//符合要求,加上‘%’后的字符串 echo mb_strlen($temp),'<br>'; echo mb_strlen($temp, 'utf-8');//符合要求
下面用java代码来实现
/** * */ package cn.com.songjy.demo; /** * @author songjianyong * */ public class LikeSqlConditionDemo { public static void main(String[] args) { System.out.println(getLikeSqlCondition(" aa a d "));//输出结果是:%a%a%a%d% } public static String getLikeSqlCondition(String condition){ if(condition==null || condition.trim().length()==0) return null; condition = trim(condition);//去除空格 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<str.length i temp="(new" stringbuilder return><br><br><br>在进行like语句查询时候用的到 <div class="clear"> </div></str.length>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Convert basic data types to strings using Java's String.valueOf() function In Java development, when we need to convert basic data types to strings, a common method is to use the valueOf() function of the String class. This function can accept parameters of basic data types and return the corresponding string representation. In this article, we will explore how to use the String.valueOf() function for basic data type conversions and provide some code examples to

Method of converting char array to string: It can be achieved by assignment. Use {char a[]=" abc d\0efg ";string s=a;} syntax to let the char array directly assign a value to string, and execute the code to complete the conversion.

The temp folder is our temporary file storage location. The system will save temporary files to this folder. If there are too many temporary files, especially when the temp folder is on the system disk, it is likely to affect the system running speed. We can solve the problem by changing the temp location. Let’s take a look below. Tutorial on changing the location of win7temp 1. First, right-click "Computer" and open "Properties" 2. Click "Advanced System Settings" on the left 3. Click "Environment Variables" below 4. Select "temp" and click "Edit" 5. Then change Just change the "Variable Value" to the path that needs to be changed.

Replace characters (strings) in a string using Java's String.replace() function In Java, strings are immutable objects, which means that once a string object is created, its value cannot be modified. However, you may encounter situations where you need to replace certain characters or strings in a string. At this time, we can use the replace() method in Java's String class to implement string replacement. The replace() method of String class has two types:

Hello everyone, today I will share with you the basic knowledge of Java: String. Needless to say the importance of the String class, it can be said to be the most used class in our back-end development, so it is necessary to talk about it.
![How to Fix Processor Thermal Trip Error in Windows 11/10 [Fix]](https://img.php.cn/upload/article/000/000/164/168169038621890.png?x-oss-process=image/resize,m_fill,h_207,w_330)
Most of the devices, such as laptops and desktops, have been heavily used by young gamers and coders for a long time. The system sometimes hangs due to application overload. This forces users to shut down their systems. This mainly happens to players who install and play heavy games. When the system tries to boot after force shutdown, it throws an error on a black screen as shown below: Below are the warnings detected during this boot. These can be viewed in the settings on the event log page. Warning: Processor thermal trip. Press any key to continue. ..These types of warning messages are always thrown when the processor temperature of a desktop or laptop exceeds its threshold temperature. Listed below are the reasons why this happens on Windows systems. Many heavy applications are in

In computers, temp means "temporary folder", which contains many temporary files; its function is to temporarily save the user's work results in the application to prevent losses caused by accidents. Deleting temp files can free up hard disk storage space, but it will be slower to open the application for the first time after deletion.

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ
