Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

eregi question.
Hi!,
I am trying to create a script which will the contents of a file and trim
away the 'top' and 'bottom' of it.
So far I have the following:--

<?php
$file = fopen("/var/www/html/file.txt", "r");
$content = file_get_contents($page);

fclose($file);

?>


I would like to add two variables to this (like $start and $end) where
anything before $start would be trimmed and anything after $end will be
trimmed.

Any idea how i can do this ?

Sorry if this is a stupid question :)

Thanks Don

Report this thread to moderator Post Follow-up to this message
Old Post
Donny D
03-27-04 04:13 AM


Re: eregi question.
Donny D <dddd@ddddnospam.com> wrote in
news:c40u9b$46k$1@titan.btinternet.com:

> Hi!,
>  I am trying to create a script which will the contents of a file and
>  trim away the 'top' and 'bottom' of it.


Don,
If PHP is resting on a Unix or Unix-like server you could use the "tail"
and "head" functions provided by the OS. Say you wanted the middle 50 lines
of a 100 line document you could do something like "head 75 | tail 50" and
if my logic/math is correct that would give you the middle 50 lines...

Hope that helps,
- Nick

Report this thread to moderator Post Follow-up to this message
Old Post
Nick Derevjanik
03-27-04 04:13 AM


Re: eregi question.
Hi,

I think what you need is the following:


$startpos = strpos($content, $start);
$content  = substr($content, $startpos);


$endpos   = strpos($content, $end);
$content  = substr($content, 0, $endpos);

Just add this code before fclose();

You will need to check for errors in case if $startpos or $endpos return
FALSE.
For more information you should read documentation on strpos() function.





"Donny D" <dddd@ddddnospam.com> wrote in message
news:c40u9b$46k$1@titan.btinternet.com...
> Hi!,
>  I am trying to create a script which will the contents of a file and trim
> away the 'top' and 'bottom' of it.
> So far I have the following:--
>
> <?php
> $file = fopen("/var/www/html/file.txt", "r");
> $content = file_get_contents($page);
>
> fclose($file);
>
> ?>
>
>
> I would like to add two variables to this (like $start and $end) where
> anything before $start would be trimmed and anything after $end will be
> trimmed.
>
> Any idea how i can do this ?
>
> Sorry if this is a stupid question :)
>
> Thanks Don



Report this thread to moderator Post Follow-up to this message
Old Post
oleg
03-28-04 04:53 AM


Re: eregi question.
Thanks that works fine!

oleg wrote:

> Hi,
>
> I think what you need is the following:
>
>
> $startpos = strpos($content, $start);
> $content  = substr($content, $startpos);
>
>
> $endpos   = strpos($content, $end);
> $content  = substr($content, 0, $endpos);
>
> Just add this code before fclose();
>
> You will need to check for errors in case if $startpos or $endpos return
> FALSE.
> For more information you should read documentation on strpos() function.
>
>
>
>
>
> "Donny D" <dddd@ddddnospam.com> wrote in message
> news:c40u9b$46k$1@titan.btinternet.com... 


Report this thread to moderator Post Follow-up to this message
Old Post
Donny D
03-29-04 10:30 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:50 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.