Jump to content

How to Echo a limited number of text


Recommended Posts

How do i Echo a limited amount of text. I fopen a txt file but i only what to echo only a certain amount. Sort of like a headlines you see in news headers.

 

<?php

$file = "hello.txt";
$fp = fopen($file, "r");
while(!feof($fp)) {
$data = fgets($fp, 1024);
echo "$data <br>";
} 
fclose($fp); 

?>

Link to comment
https://forums.phpfreaks.com/topic/104789-how-to-echo-a-limited-number-of-text/
Share on other sites

Now i'm trying to make a br every 75, which it does but it removed the 50 charactor limit

 

What it looks like:

http://www.jaybirdfolio.com/display%20image.php

 

<?php

$file = "hello.txt";
$fp = fopen($file, "r");
while(!feof($fp)) {
$data = fgets($fp, 1024);
$text = $data;
$newtext = wordwrap($data, 75, "<br />\n");
echo $newtext;
echo substr($newtext,0,50); // Echos first 50 characters
} 
fclose($fp); 

?>

Eventualy i'm going to try to place into a div.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.