php筛选四字母代码

avatar admin 2022-01-03 15:23 15次浏览 评论已关闭

话不多说,上代码:

<!doctype html>
<html>
    <head>
	<title>四位.club域名</title>
        <meta charset="utf-8">
    </head>
    <body>
<?php
/*
test.txt文件内容为:

10ferents.club
1901.club
1992.club
288cash.club
2nd.club
365gold.club
3dscanning.club
406disco.club
99fitness.club
abuo9i8n3.club
abuo9i8n5.club
abur5t6b2.club
abut6y7n1.club
abut6y7n4.club
abut6y7n7.club
abuy7u8n6.club
1234.club
abcd.club


4.txt只有:
abcd.club

正确的答案应该是:
1901.club 
1992.club 
1234.club 
abcd.club 
*/
$handle=fopen("test.txt","r");
while(!feof($handle)){
$str=fgets($handle);
if(stripos($str,".")==4){
file_put_contents("4.txt",$str,FILE_APPEND);
}
}
?>
</select><BR>
</body>
</html>

例二:

<?php
/*
*我有一个文本文件file.txt
*内容是每行四个字符:
*fdsa
*vffd
*csfe
*zfvs
*gfge
*fdsk
*dcfa
*zdco
*fdau
*dpkl
*fpyt
*
*这样的结构,有几十万行.我想把他们分类,带aeoiu任一个字符或者多个元音字符的写在
*one.txt文件中,不带aeoiu中的任何一个字符放在文件two.txt中.
*/
if(!file_exists("one.txt")){
fopen("one.txt",'wb');
}
if(!file_exists("two.txt")){
fopen("two.txt",'wb');
}


$file = file_get_contents('file.txt', 'r+'); 
$one = $two =[];
$lines = explode("\n", $file); 
foreach ($lines as $value) { 
if (preg_match('/[aeiouv]/S', $value)) { 
// if (strpbrk($line, 'aeiou') !== false) { 
// if (strcspn($line, 'aeiou') < strlen($line)) { 
$one[] = trim("$value"); 
} 
else { 
$two[] = trim("$value");  
} 
} 
$one = implode("\n", $one); 
$two = implode("\n", $two); 
file_put_contents("one.txt", $one); 
file_put_contents("two.txt", $two);

?>

 

标签:
发表评论
请先登录后再评论~