日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 过滤中英文以外,PHP-php过滤重复中英文字符串

發布時間:2024/9/30 php 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 过滤中英文以外,PHP-php过滤重复中英文字符串 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

個人覺得就是2點優化

1、分塊,分塊以后遍歷不用每次從頭開始定位

2、快速定位,可以將字符驗證改成整數驗證

$str = "中國人abc蓅氓澮娬朮國人ac娬朮";

$str = str_pad('', 1024*1024, $str);

mb_internal_encoding("UTF-8");

$time = time();

$len = mb_strlen($str);

// 按照千字一組

$group_size = 500;

$group_total = ceil($len / $group_size);

$chars = array();

$result = '';

for($i = 0; $i < $group_total; $i++) {

$tmp = mb_substr($str, 0, $group_size);

// 這里如果處理1組字符了,就將前1組理掉

$str = mb_substr($str, $group_size, $len > $group_size ? $len - $group_size : $len);

$len = mb_strlen($str);

if($i % 50 == 49) {

printf("process %d groups, total %d groups, run time %dn", $i + 1, $group_total, time()-$time);

}

// 處理字符

$tmp_len = $i < $group_total - 2 ? $group_size : mb_strlen($tmp);

for($j = 0; $j < $tmp_len; $j++) {

$char = mb_substr($str, $i, 1);

$num = hexdec(bin2hex($char));

if(isset($chars[$num])) {

continue;

} else {

$chars[$num] = 1;

$result .= $char;

}

}

}

var_dump($result);

輸出

process 50 groups, total 870 groups, run time 4

process 100 groups, total 870 groups, run time 9

process 150 groups, total 870 groups, run time 13

process 200 groups, total 870 groups, run time 18

process 250 groups, total 870 groups, run time 22

process 300 groups, total 870 groups, run time 27

process 350 groups, total 870 groups, run time 31

process 400 groups, total 870 groups, run time 35

process 450 groups, total 870 groups, run time 40

process 500 groups, total 870 groups, run time 44

process 550 groups, total 870 groups, run time 48

process 600 groups, total 870 groups, run time 52

process 650 groups, total 870 groups, run time 56

process 700 groups, total 870 groups, run time 60

process 750 groups, total 870 groups, run time 65

process 800 groups, total 870 groups, run time 69

process 850 groups, total 870 groups, run time 73

string(27) "氓娬蓅cab人國朮中澮"

總結

以上是生活随笔為你收集整理的php 过滤中英文以外,PHP-php过滤重复中英文字符串的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。