2016-09-20 8 views
-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"); 
    } 
?> 
+0

あなたは試してみることができます:echo substr($ fileContens、0,200); –

答えて

2

file_get_contents()$maxlenパラメータがあります。

PHP manualを参照してください。

関連する問題