Day: April 30, 2015

MySQL替换函数REPLACE替换字符串方法

在网站搬家、更换域名的时候,Drupal和Wordpress都是用的MySQL的数据库,很多配置信息是写在MySQL数据库里面的。我们需要将数据库里面的相关配置信息替换成新空间或域名的信息。这时我们就要用到MySQL的字符串替换函数Replace了。 MySQL Replace 替换函数语法: update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, "find this string", "replace found string with this string"); Replace 替换函数案例: update client_table set url = replace(url, "py… Read More

用PHP正则表达式清除字符串的连续空白 (php 正则 只保留一个空格)

PHP方法: <?php $str = " This line containstliberal rn use of whitespace.nn"; // First remove the leading/trailing whitespace //去掉開始和結束的空白 $str = trim($str); // Now remove any doubled-up whitespace //去掉跟隨別的擠在一塊的空白 $str = preg_replace('/s(?=s)/', '', $str); // Finally, replace any non-space whitespace, with a space //最後,去掉非space 的空白,用一個空格代替 $st… Read More

MYSQL: 查询数据库字符串是否被包含在另一个字符串中 Search where column value is within a string

CREATE TABLE myTable( id INT NOT NULL AUTO_INCREMENT PRIMARy KEY, name VARCHAR(100), city VARCHAR(100)); INSERT INTO myTable (name, city) VALUES ('test', 'anza'); INSERT INTO myTable (name, city) VALUES ('fish', 'riverside');   SELECT * FROM myTable WHERE 'anza city' LIKE CONCAT('%', city, '%') OR 'riverside county' LIKE CONCAT('%', city, '%… Read More