-1
我想從本地文件讀取前200個字符,但是,我的代碼正在讀取我的文本文件的所有內容。如何在php中限制文本長度'file_get_contents'並提供'Read more'鏈接
<?php
$connection= new mysqli($DB_host,$DB_user,$DB_pass,$DB_name);
$query = mysqli_query($connection,"SELECT * FROM new_record ORDER BY id");
while ($row = mysqli_fetch_array($query)) {
$fileName = $row['name'];
$fileContents = file_get_contents("txt/$fileName");
echo ("$fileContents");
}
?>
你可以嘗試:echo substr($ fileContens,0,200); –