案例描述:
找出文字檔案(input.txt)中所有符合下面條件的字元
1. 是乙個小寫字母,並且
2.兩側各有且只有三個大寫字母(考慮換行符) 例如xaaabaaad中的b
首先在同級目錄下建立input.txt
然後在檔案中,敲一些英文本母(可以有規律,也可以無規律)
如:
asadfsaxaaabaaadrytaasd
再建立乙個php檔案
**如下:
<?php
header('content-type:text/html;charset=utf8 ');
function getlower($data)
}else if($i == $length-3)
}else if($i>3 && $i<$length-3)
}else
if($flag)}}
return $str;
}//公共當前字元的前三後和三個
function getflag($data,$i)}}
return $flag;
}/* 判斷是否是大寫字母*/
function isupper($s)else
}$res ='';
$d=file_get_contents('input.txt');
$res = getlower(str_replace("\r\n","",$d));
echo $res;
效果如下(瀏覽器輸出):
bda
從檔案中讀取字串
問題 如何從磁碟檔案中讀取字串兒,然後按行將其倒序輸出?下面一段材料取自陳壽 三國志 卷三十五諸葛亮傳,我把它分成了10段,現在要求從磁碟檔案中讀取這段文字,然後按照一定的規則倒序輸出。比如說,如果我要求輸出3行,系統會依次輸出第10 9 8三行 如果我要求輸出20行,則系統會依次輸出10 9 8 ...
PHP如何從txt檔案中讀取資料詳解
目錄 1 對檔案操作時首先要開啟檔案,開啟檔案用 fopen 函式,語法是 fopen filename,mode,include path,context 2 對檔案操作結束後應該關閉這個檔案,使用函式 fclose 例如 有三個函式可以使用,分別是 readfile 函式 file 函式 fil...
從XML檔案中讀取資料
using system using system.data using system.configuration using system.web using system.web.security using system.web.ui using system.web.ui.webcontro...