Re: read "include" part of a file, I have a script problem??
| From: | OntheAve | Date: | Mon, 05 Nov 2001 23:14:00 +0000 |
| Subject: | Re: read "include" part of a file, I have a script problem?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-73522@lists.php.net to get a copy of this message | ||
Works Great. Thanks. I wrote that in ASP, but sometimes i have a hard time
to switch from one to the other. Although I am seriously considering droping
ASP, PHP being far more powerful.
Thanks again!
----- Original Message -----
From: "Curt A. Gilman" <curt@gilm.net>
To: "Ontheave" <ontheave@yahoo.com>
Sent: Monday, November 05, 2001 5:07 PM
Subject: Re: read "include" part of a file, I have a script problem??
> I think you have a several problems here:
>
> (1) The $Key variable below will contain the line numbers from your
> begin.inc file. As it is now, it will never match $BeginIt or $EndIt.
>
> (2) The first pass through to loop won't have any values for $Key or $Val
at
> all, since they are evaluated after each iteration, using the do ... while
> construct.
>
> (3) The lines that you read into the $Val variable will have line feeds on
> the end of them, so you'll need to remove them.
>
> (4) The only line that will echo is when $Key (should be $Val) equals
> $BeginIt. Anything else after will be ignored.
>
> You probably want something more like this (I haven't tested this!):
>
> $FileName = "begin.inc";
> $Content = file($FileName);
> $BeginIt = "<!--beginPHP-->";
> $EndIt = "<!--endPHP-->";
>
> $BeginFlag = 0;
> while( list( $Key, $Val ) = each( $Content ) )
> {
> if( chop( $Val ) == $EndIt )
> {
> break;
> }
> if( $BeginFlag == 1 )
> {
> echo $Val;
> }
> if( chop( $Val ) == $BeginIt )
> {
> $BeginFlag = 1;
> }
> };
>
>
> "Ontheave" <ontheave@yahoo.com> wrote in message
> news:00d501c16634$5e1a50c0$7801a8c0@megapathdsl.net...
> Hi,
> I have my file: begin.inc, from which I want to include a part in my php
> page. I have included this part between the tags:
> "<!--BeginPHP-->" &
> "<!--EndPHP-->", but I can't have my loop working.
> Here is What I have written:
>
> $FileName = "begin.inc";
> $Content = file($FileName);
> $BeginIt = "<!--beginPHP-->";
> $EndIt = "<!--endPHP-->";
>
> do {
> if ($Key == $BeginIt) {
> echo $Val;
> } elseif ($Key == $EndIt) {
> Break;
> }
> } while(list($Key,$Val) = each($Content) );
>
> What is wrong with my script?
>
>
>
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com