mysqlurlencode编码后怎么精确搜索
答案:2 悬赏:0 手机版
解决时间 2021-12-21 22:30
- 提问者网友:ミ烙印ゝ
- 2021-12-21 10:49
mysqlurlencode编码后怎么精确搜索
最佳答案
- 五星知识达人网友:忘川信使
- 2021-12-21 12:08
view sourceprint?
01.
DELIMITER ;
02.
03.
DROP FUNCTION IF EXISTS urlencode;
04.
05.
DELIMITER |
06.
07.
CREATE FUNCTION urlencode (s VARCHAr(4096)) RETURNS VARCHAr(4096)08.
DETERMINISTIC
09.
CONTAINS SQL
10.
BEGIN
11.
DECLARE c VARCHAr(4096) DEFAULT '';
12.
DECLARE pointer INT DEFAULT 1;
13.
DECLARE s2 VARCHAr(4096) DEFAULT '';
14.
15.
IF ISNULL(s) THEN
16.
RETURN NULL;
17.
ELSE
18.
SET s2 = '';
19.
WHILE pointer <= length(s) DO
20.
SET c = MId(s,pointer,1);
21.
IF c = ' ' THEN
22.
SET c = '+';
23.
ELSEIF NOT (ASCIi(c) BETWEEN 48 AND 57 OR24.
ASCIi(c) BETWEEN 65 AND 90 OR
25.
ASCIi(c) BETWEEN 97 AND 122) THEN
26.
SET c = concat("%",LPAd(CONv(ASCIi(c),10,16),2,0));27.
END IF;
28.
SET s2 = CONCAt(s2,c);
29.
SET pointer = pointer + 1;
30.
END while;
31.
END IF;
32.
RETURN s2;
33.
END;
34.
|
35.
DELIMITER ;
view sourceprint?
01.
DROP FUNCTION IF EXISTS urldecode;
02.
03.
DELIMITER |
04.
05.
CREATE FUNCTION urldecode (s VARCHAr(4096)) RETURNS VARCHAr(4096)06.
DETERMINISTIC
07.
CONTAINS SQL
08.
BEGIN
09.
DECLARE c VARCHAr(4096) DEFAULT '';
10.
DECLARE pointer INT DEFAULT 1;
11.
DECLARE h CHAr(2);
12.
DECLARE h1 CHAr(1);
13.
DECLARE h2 CHAr(1);
14.
DECLARE s2 VARCHAr(4096) DEFAULT '';
15.
16.
IF ISNULL(s) THEN
17.
RETURN NULL;
18.
ELSE
19.
SET s2 = '';
20.
WHILE pointer <= LENGTH(s) DO
21.
SET c = MId(s,pointer,1);
22.
IF c = '+' THEN
23.
SET c = ' ';
24.
ELSEIF c = '%' AND pointer + 2 <= LENGTH(s) THEN25.
SET h1 = LOWER(MId(s,pointer+1,1));
26.
SET h2 = LOWER(MId(s,pointer+2,1));
27.
IF (h1 BETWEEN '0' AND '9' OR h1 BETWEEN 'a' AND 'f')28.
AND
29.
(h2 BETWEEN '0' AND '9' OR h2 BETWEEN 'a' AND 'f')30.
THEN
31.
SET h = CONCAt(h1,h2);
32.
SET pointer = pointer + 2;
33.
SET c = CHAr(CONv(h,16,10));
34.
END IF;
35.
END IF;
36.
SET s2 = CONCAt(s2,c);
37.
SET pointer = pointer + 1;
38.
END while;
39.
END IF;
40.
RETURN s2;
41.
END;
42.
43.
|
44.
45.
DELIMITER ;
当一个字符串经过多次 urlencode 处理之后,可以使用 multiurldecode来解码,它将多次调用 urldecode来解码,直到没有需要解码的字符www.it165.net
view sourceprint?
01.
DELIMITER ;
02.
03.
DROP FUNCTION IF EXISTS multiurldecode;
04.
05.
DELIMITER |
06.
07.
CREATE FUNCTION multiurldecode (s VARCHAr(4096)) RETURNS VARCHAr(4096)08.
DETERMINISTIC
09.
CONTAINS SQL
10.
BEGIN
11.
DECLARE pr VARCHAr(4096) DEFAULT '';
12.
IF ISNULL(s) THEN
13.
RETURN NULL;
14.
END IF;
15.
REPEAT
16.
SET pr = s;
17.
SELECT urldecode(s) INTO s;
18.
UNTIL pr = s END REPEAT;
19.
RETURN s;
20.
END;
21.
22.
|
23.
24.
DELIMITER ;
01.
DELIMITER ;
02.
03.
DROP FUNCTION IF EXISTS urlencode;
04.
05.
DELIMITER |
06.
07.
CREATE FUNCTION urlencode (s VARCHAr(4096)) RETURNS VARCHAr(4096)08.
DETERMINISTIC
09.
CONTAINS SQL
10.
BEGIN
11.
DECLARE c VARCHAr(4096) DEFAULT '';
12.
DECLARE pointer INT DEFAULT 1;
13.
DECLARE s2 VARCHAr(4096) DEFAULT '';
14.
15.
IF ISNULL(s) THEN
16.
RETURN NULL;
17.
ELSE
18.
SET s2 = '';
19.
WHILE pointer <= length(s) DO
20.
SET c = MId(s,pointer,1);
21.
IF c = ' ' THEN
22.
SET c = '+';
23.
ELSEIF NOT (ASCIi(c) BETWEEN 48 AND 57 OR24.
ASCIi(c) BETWEEN 65 AND 90 OR
25.
ASCIi(c) BETWEEN 97 AND 122) THEN
26.
SET c = concat("%",LPAd(CONv(ASCIi(c),10,16),2,0));27.
END IF;
28.
SET s2 = CONCAt(s2,c);
29.
SET pointer = pointer + 1;
30.
END while;
31.
END IF;
32.
RETURN s2;
33.
END;
34.
|
35.
DELIMITER ;
view sourceprint?
01.
DROP FUNCTION IF EXISTS urldecode;
02.
03.
DELIMITER |
04.
05.
CREATE FUNCTION urldecode (s VARCHAr(4096)) RETURNS VARCHAr(4096)06.
DETERMINISTIC
07.
CONTAINS SQL
08.
BEGIN
09.
DECLARE c VARCHAr(4096) DEFAULT '';
10.
DECLARE pointer INT DEFAULT 1;
11.
DECLARE h CHAr(2);
12.
DECLARE h1 CHAr(1);
13.
DECLARE h2 CHAr(1);
14.
DECLARE s2 VARCHAr(4096) DEFAULT '';
15.
16.
IF ISNULL(s) THEN
17.
RETURN NULL;
18.
ELSE
19.
SET s2 = '';
20.
WHILE pointer <= LENGTH(s) DO
21.
SET c = MId(s,pointer,1);
22.
IF c = '+' THEN
23.
SET c = ' ';
24.
ELSEIF c = '%' AND pointer + 2 <= LENGTH(s) THEN25.
SET h1 = LOWER(MId(s,pointer+1,1));
26.
SET h2 = LOWER(MId(s,pointer+2,1));
27.
IF (h1 BETWEEN '0' AND '9' OR h1 BETWEEN 'a' AND 'f')28.
AND
29.
(h2 BETWEEN '0' AND '9' OR h2 BETWEEN 'a' AND 'f')30.
THEN
31.
SET h = CONCAt(h1,h2);
32.
SET pointer = pointer + 2;
33.
SET c = CHAr(CONv(h,16,10));
34.
END IF;
35.
END IF;
36.
SET s2 = CONCAt(s2,c);
37.
SET pointer = pointer + 1;
38.
END while;
39.
END IF;
40.
RETURN s2;
41.
END;
42.
43.
|
44.
45.
DELIMITER ;
当一个字符串经过多次 urlencode 处理之后,可以使用 multiurldecode来解码,它将多次调用 urldecode来解码,直到没有需要解码的字符www.it165.net
view sourceprint?
01.
DELIMITER ;
02.
03.
DROP FUNCTION IF EXISTS multiurldecode;
04.
05.
DELIMITER |
06.
07.
CREATE FUNCTION multiurldecode (s VARCHAr(4096)) RETURNS VARCHAr(4096)08.
DETERMINISTIC
09.
CONTAINS SQL
10.
BEGIN
11.
DECLARE pr VARCHAr(4096) DEFAULT '';
12.
IF ISNULL(s) THEN
13.
RETURN NULL;
14.
END IF;
15.
REPEAT
16.
SET pr = s;
17.
SELECT urldecode(s) INTO s;
18.
UNTIL pr = s END REPEAT;
19.
RETURN s;
20.
END;
21.
22.
|
23.
24.
DELIMITER ;
全部回答
- 1楼网友:蓝房子
- 2021-12-21 13:46
$list=array("amount"=>urlencode(iconv('gb2312','utf-8', $row['amount'])));
echo json_encode($list); 如果你数据库的编码是gbk的话使用以上代码,如果是utf8则不必使用iconv
$list=array("amount"=>$row['amount']);
echo json_encode($list);
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯