NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Shortening (HTML/PHP)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-17-2007, 05:34 AM THREAD STARTER               #1 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Shortening (HTML/PHP)


Hey all. I'm sure this is quite simple but basically I'm displaying a text file in a textarea but only want to display a certain number of lines. I'm using 'fread' but I think you can only set the number of bytes rather than number of lines. Anyway, there are three ways I'm looking at doing it:

1. With the fread function, somehow.
2. When the contents of the text file are stored as a variable.
3. ..or with the 'textarea' field itself.

Just need a little bit of guidance.

Thanks
__________________
Encenta - Amazon Associates CMS
Encenta.com is offline  
Old 05-17-2007, 06:03 AM   #2 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Something like this:
PHP Code:
<?php
????: NamePros.com http://www.namepros.com/programming/328866-shortening-html-php.html

$lines 
preg_split("#\n#"file_get_contents('yourfile.txt'), -1PREG_SPLIT_NO_EMPTY);
$data '';
$limit 5;

for (
$i 0$i <= $limit$i++)
{
    
$data .= trim($lines[$i]) . "\n";
}

unset(
$lines);

?>
Eric is offline  
Old 05-17-2007, 10:16 AM THREAD STARTER               #3 (permalink)
SQLdumpster.com
 
Encenta.com's Avatar
Join Date: Jun 2005
Location: West Sussex, UK
Posts: 573
Encenta.com has a spectacular aura aboutEncenta.com has a spectacular aura about
 




Thanks for the help. Small donation sent
__________________
Encenta - Amazon Associates CMS
Encenta.com is offline  
Old 05-17-2007, 12:20 PM   #4 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




Small update for SV's code.

You can replace:
PHP Code:
$lines preg_split("#\n#"file_get_contents('yourfile.txt'), -1PREG_SPLIT_NO_EMPTY); 
????: NamePros.com http://www.namepros.com/showthread.php?t=328866
With:
PHP Code:
$lines file('yourfile.txt'); 
I would assume my way is faster as it only uses 1 function.
Barrucadu is offline  
Old 05-17-2007, 03:30 PM   #5 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,552
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
http://php.net/manual/en/function.fgets.php:
Reading a file line by line
PHP Code:
<?php
$handle 
= @fopen("/tmp/inputfile.txt""r");
if (
$handle) {
    while (!
feof($handle)) {
        
$buffer fgets($handle4096);
        echo 
$buffer;
    }
    
fclose($handle);
}
?>
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:07 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger