forked from hanlintao/translatorscanprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path代码 7-6.php
More file actions
41 lines (40 loc) · 1.76 KB
/
代码 7-6.php
File metadata and controls
41 lines (40 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php include "shared/head.php"; ?>
<form action="" method="POST">
<table>
<tr>
<td><textarea rows="10" name ="text">北京语言大学(Beijing Language and Culture University, BLCU)成立于1962年。</textarea></td>
</tr>
<tr>
<td><button type="submit">开始统计</button></td>
</tr>
</table>
</form>
<?php
$text=$_POST["text"];
echo "英文单词个数为:".str_word_count($text)."<br>";
echo "英文单词包括:";
$english_char_num="";
foreach(str_word_count($text,1) as $english)
{
$english_char_num = $english_char_num + strlen($english);
echo $english." ";
}
echo "<br>"."英文单词字符总数为:".$english_char_num."<br>";
echo "全文空格个数为:".substr_count($text," ")."<br>";
$chinese_punct= ",。、!?:;﹑•"…‘’“”〝〞∕¦‖— 〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔!¡?¿﹖﹌﹏﹋'´ˊˋ―﹫︳︴¯_ ̄﹢﹦﹤‐¬˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼()";
$pattern = array("/[[:punct:]]/i", "/['.$chinese_punct.']/u", "/[[:alnum:]]/", "/[[:space:]]/",);
$chinese = preg_replace($pattern, '', $text);
echo "中文文本包括:".$chinese."<br>";
echo "中文字数为:".mb_strlen($chinese, "utf8")."<br>";
preg_match_all("/\d+/",$text,$matches);
echo "数字包括:";
$number_char_num="";
foreach($matches[0] as $number)
{
$number_char_num=$number_char_num+strlen($number);
echo $number." ";
}
echo "<br>"."数字个数为:".count($matches[0])."<br>";
echo "数字字符总数为:".$number_char_num."<br>";
?>
<?php include "shared/foot.php"; ?>