當前位置:首頁 » 凈水方式 » mysql過濾字元串

mysql過濾字元串

發布時間: 2021-02-05 01:05:20

⑴ mysql如何過濾特殊字元用PHP語言。高分求助,給補分

function deletehtml($str) {
$str = trim($str);
$str = preg_replace("</P>","1234a3211",$str);
$str = preg_replace("</p>","1234a3211",$str);
$str = preg_replace("<br/>","1234a3211",$str);

$str = preg_replace("/<(.[^>]*)>/","",$str);
$str = preg_replace("/([\r\n])[\s]+/","",$str);
$str = preg_replace("/-->/","",$str);
$str = preg_replace("/<!--.*/","",$str);
$str = preg_replace("/&(quot|#34);/","",$str);

$str = preg_replace("/&(amp|#38);/", "/&/",$str);
$str = preg_replace("/&(lt|#60);/", "/</",$str);
$str = preg_replace("/&(gt|#62);/", ">",$str);
$str = preg_replace("/&(nbsp|#160);/", "",$str);
$str = preg_replace("/&(iexcl|#161);/", "/\xa1/",$str);
$str = preg_replace("/&(cent|#162);/", "/\xa2/",$str);
$str = preg_replace("/&(pound|#163);/", "/\xa3/",$str);
$str = preg_replace("/&(|#169);/", "/\xa9/",$str);
$str = preg_replace("/&#(\d+);/", "",$str);

$str = preg_replace("/</", "",$str);
$str = preg_replace("/>/", "",$str);
$str = preg_replace("/\r\n/", "",$str);
$str = preg_replace("/1234a3211/", "/<br/>/",$str);

return $str;
}

⑵ mysql去掉字元串中重復的部分

這個表應該有個id吧
delete from tbl where id not in
(select id from (select id from tbl group by month having count(month)>1) as a)
mysql不支持在同一個表查詢之後,做修改、刪除內操作。
刪除的思路是,
1、select id from tbl group by month having count(month)>1 找到需容要保留的id
2、 select id from (select id from tblgroup by month having count(month)>1) as a
把需要保留的結果指定新的表名,找到保留id
3、執行刪除操作

⑶ mysql如何進行字元串處理

方法/步驟
首先,計算字元串的字元數,可以用char_length()函數,代碼如下:版
select 'zhangsan',char_length('zhangsan');
如下圖所示:

字元串中的length()函數,用權來計算字元串的長度,代碼如下:
select 'zhangsan',length('zhangsan1111');
如下圖所示:
字元串函數中有時需要將幾個不同的字元串拼接在一起,這時可以利用concat(a1,a2,...)和concat_ws(b,b1,b2,...),可以將各字元串合並成一個字元串,代碼如下:
select concat('zhang','san','feng');
select concat_ws('*','zhang','san','feng');

⑷ mysql 去除指定字元串前的內容

updateaSETname=SUBSTRING(name,1,casewhenLOCATE('/',name)!=0thenLOCATE('/',name)-1ELSELENGTH(`name`)END);a:改成你的表名name是要處版理的欄位權

⑸ mysql 中欄位怎樣剔除中文字元串

用正則表達式替換即可

⑹ mysql截取刪除字元串

在使用mysql時,常會進行字元串截取,字元替換,取子串等。具體介紹如下:

1、從左開始截取字元串
left(str, length) 說明:left(被截取欄位,截取長度)
例:select left('charfunction', 5) as result from al;
輸出: charf
2、從右開始截取字元串
right(str, length) 說明:right(被截取欄位,截取長度)
例:select right('charfunction',5) as result from al;
輸出:ction

3、截取字元串,這里分兩種情形,分別是從頭截取和中間開始截取
substring(str, pos) 說明:substring(被截取欄位,從第幾位開始截取)
substring(str, pos, length) substring(被截取欄位,從第幾位開始截取,截取長度)
例:select substring('charfunction', 5) as result from al; 輸出:unction
select substring('charfunction',5,5) as result from al; 輸出:uncti
(註:如果位數是負數 如-5 則是從後倒數位數,到字元串結束或截取的長度)

4、替換相關字元
replace(str, old, new)將 str中的 old串替換成new字元串
例:select replace ('charfunction','n','WW') as result from al;
輸出: charfuWWctioWW
具體使用方法請結合數據表練習領會。

⑺ mysql 刪除 某欄位中的指定字元串

用replace把要刪除的字元替換成空串就可以了

update 表名 set 欄位=replace(欄位,'要刪除的串','') where 條件

⑻ mysql 正則表達式 如何截取字元串中指定格式的字元

代碼如下:
CREATE PROCEDURE sp_str
(
IN p_str VARCHAR(50), /*原始字元串*/
IN p_begin_str VARCHAR(50), /*要匹配的起始字元串*/
IN p_end_str VARCHAR(50)) /*要匹配的結束字元串*/
OUT p_result VARCHAR(50)) /*返回結果*/
NOT DETERMINISTIC
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE m_len INT DEFAULT 0;
DECLARE m_index INT DEFAULT 0;
/*計算第一個匹配字元串的索引位置*/
select locate(p_begin_str,p_str)+char_length(p_begin_str) into m_index;
/*計算第一個匹配字元串的長度*/
select locate(p_end_str,p_str,m_index) into m_len;
select SUBSTRING(p_str,m_index,m_len-m_index) INTO p_result ;
END;

執行:
CALL sp_str('[]abcd[12345]aa[]ss','abcd[',']',@result);
返回值 @result 為12345
call sp_str('[]abcd[sdww]aa[]ss','abcd[',']',@result);
返回值 @result 為sdww
如果不用存儲過程,可以直接寫sql語句實現:

代碼如下:
select SUBSTRING(
']abcd[12345]111[]',
locate('abcd[',']abcd[12345]111[]')+CHAR_LENGTH('abcd['),
locate(']',']abcd[12345]111[]',CHAR_LENGTH('abcd['))-
(select locate('abcd[',']abcd[12345]111[]')+CHAR_LENGTH('abcd['))
)

返回值為 12345
關於mysql的函數介紹:
CHAR_LENGTH(str)
返回字元串str的長度。
LOCATE(substr,str)
POSITION(substr IN str)
返回子串substr在字元串str第一個出現的位置,如果substr不是在str裡面,返回0.
mysql> select LOCATE('bar', 'foobarbar');
-> 4
mysql> select LOCATE('xbar', 'foobar');
-> 0
該函數是多位元組可靠的。 LOCATE(substr,str,pos)
返回子串substr在字元串str第一個出現的位置,從位置pos開始。如果substr不是在str裡面,返回0。
mysql> select LOCATE('bar', 'foobarbar',5);
-> 7
這函數是多位元組可靠的。
SUBSTRING(str,pos,len)
SUBSTRING(str FROM pos FOR len)
MID(str,pos,len)
從字元串str返回一個len個字元的子串,從位置pos開始。使用FROM的變種形式是ANSI SQL92語法。
mysql> select SUBSTRING('Quadratically',5,6);
-> 'ratica'
該函數是多位元組可靠的。
SUBSTRING(str,pos)

⑼ mysql怎麼截取欄位的字元串

MySQL裡面可以截取字元串的方法還是很豐富的:

#從左側截取,截取指內定長度容
left(str,len)
#右側
right(str,len)
#從中間某個位置截取指定長度
MID(str,pos,len)
#同上
SUBSTR(strFROMposFORlen)
#從某個位置開始之後所有的字元
SUBSTR(str,pos)

⑽ mysql 中用正則表達式如何取一個字元串中指定的欄位,

substring_index(input,split,index):input為要截取的字元,split為分隔符,Index為要截取第index個分隔符左(為正)或右(index為負)的字元串。

舉例:

'Provider="RiskManagement" finalScore="65" RGID="100397278"'//獲取finalScore的值

1、獲取finalScore右邊的字元

select substring_index('Provider="RiskManagement" finalScore="65" RGID="100397278"','finalScore="',-1);

2、再獲取" RGID="左邊的字元

select substring_index(substring_index('Provider="RiskManagement" finalScore="65" RGID="100397278"','finalScore="',-1),'" RGID="',1);

(10)mysql過濾字元串擴展閱讀

MySQL 字元串截取函數:left(), right(), substring(), substring_index()。還有 mid(), substr()。其中,mid(), substr() 等價於 substring() 函數,substring() 的功能非常強大和靈活。

1、字元串截取:left(str, length)

mysql> select left('sqlstudy.com', 3);

| left('sqlstudy.com', 3) |

| sql |

2、字元串截取:right(str, length)

mysql> select right('sqlstudy.com', 3);

| right('sqlstudy.com', 3) |

| com |

熱點內容
丁度巴拉斯情人電影推薦 發布:2024-08-19 09:13:07 瀏覽:886
類似深水的露點電影 發布:2024-08-19 09:10:12 瀏覽:80
《消失的眼角膜》2電影 發布:2024-08-19 08:34:43 瀏覽:878
私人影院什麼電影好看 發布:2024-08-19 08:33:32 瀏覽:593
干 B 發布:2024-08-19 08:30:21 瀏覽:910
夜晚看片網站 發布:2024-08-19 08:20:59 瀏覽:440
台灣男同電影《越界》 發布:2024-08-19 08:04:35 瀏覽:290
看電影選座位追女孩 發布:2024-08-19 07:54:42 瀏覽:975
日本a級愛情 發布:2024-08-19 07:30:38 瀏覽:832
生活中的瑪麗類似電影 發布:2024-08-19 07:26:46 瀏覽:239