Home > Backend Development > PHP Tutorial > update go_member set username = replace(name,'non-Chinese characters',''); How to write non-Chinese characters?

update go_member set username = replace(name,'non-Chinese characters',''); How to write non-Chinese characters?

WBOY
Release: 2016-08-04 09:19:45
Original
1328 people have browsed it

update go_member set username = replace(username,'non-Chinese characters','');

I want to replace the name in the database. As long as the name does not contain numbers, letters or Chinese characters (that is, special characters are removed), all names will be replaced. How to do it? ? ?

The database is MySQL

Reply content:

update go_member set username = replace(username,'non-Chinese characters','');

I want to replace the name in the database. As long as the name does not contain numbers, letters or Chinese characters (that is, special characters are removed), all names will be replaced. How to do it? ? ?

The database is MySQL

mysql regular matching, it is good to try my local test
update go_member set username= '' where username not REGEXP '[[:alpha:]]|[0-9]|[a-z,A-Z]'

----Thank you for the invitation----
Idea 1 (not recommended): Stupid method, first find out all the data, then filter the results (filter non-Chinese characters) and record the IDs of these data, and then update

Idea 2 (recommended): Use regular expressions in SQL. Regular expressions can also be used in SQL. It depends on what database you use. Specific databases have different syntaxes. This depends on your situation, just Google it. For example, Oracle has these four regular expression functions: regexp_like, regexp_replace, regexp_substr, and regexp_instr.
Example:
select
from emp where regexp_like(ename,'^a[a-z ]n$'); You can find the lines starting with a and ending with n in ename

Based on the above solutions, you can go to Google to figure it out yourself. . . . Hope it helps you.

If you use PHP, it is best to use regular expressions in PHP to match and filter results. Although, as mentioned above, MySQL supports regular query statements, the efficiency will be lower.

The regular rule for Chinese is:
/([u4e00-u9fa5])/u, then the regular rule for filtering non-Chinese is: /([^u4e00-u9fa5])/u

Provide a Chinese character regular pattern under php utf-8

<code><?php
$str = "one中国你好two";
$preg = "/\p{Han}+/u";
$result = preg_replace($preg, '', $str);
var_dump($result);</code>
Copy after login
p in lowercase matches Chinese characters, and uppercase P matches non-Chinese characters

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template