Connecting Tech Pros Worldwide Forums | Help | Site Map

require file is causing error

NotGiven
Guest
 
Posts: n/a
#1: Jul 17 '05
I have a function in a file called tCalc.php, here's the content:

<?php
function calcElapsedTime($time)
{ // calculate elapsed time (in seconds!)
$diff = time()-$time;
$daysDiff = floor($diff/60/60/24);
$diff -= $daysDiff*60*60*24;
$hrsDiff = floor($diff/60/60);
$diff -= $hrsDiff*60*60;
$minsDiff = floor($diff/60);
$diff -= $minsDiff*60;
$secsDiff = $diff;
return ('(elapsed time '.$daysDiff.'d '.$hrsDiff.'h '.$minsDiff.'m
'.$secsDiff.'s)');
}
?>

The function works fine when in the page2.php. But when I take it out and
add this line, it doesn't process:
require_once('tCalc.php');

tCalc.php is in the same directory as page2.php.

Why is it not working?



Shawn Wilson
Guest
 
Posts: n/a
#2: Jul 17 '05

re: require file is causing error


NotGiven wrote:[color=blue]
>
> I have a function in a file called tCalc.php, here's the content:
>
> <?php
> function calcElapsedTime($time)
> { // calculate elapsed time (in seconds!)
> $diff = time()-$time;
> $daysDiff = floor($diff/60/60/24);
> $diff -= $daysDiff*60*60*24;
> $hrsDiff = floor($diff/60/60);
> $diff -= $hrsDiff*60*60;
> $minsDiff = floor($diff/60);
> $diff -= $minsDiff*60;
> $secsDiff = $diff;
> return ('(elapsed time '.$daysDiff.'d '.$hrsDiff.'h '.$minsDiff.'m
> '.$secsDiff.'s)');
> }
> ?>
>
> The function works fine when in the page2.php. But when I take it out and
> add this line, it doesn't process:
> require_once('tCalc.php');
>
> tCalc.php is in the same directory as page2.php.
>
> Why is it not working?[/color]

Are you getting an error? If not, put error_reporting(E_ALL); on the first line
of page2.php.

Are you requiring the page before you're calling the function? Are you sure
your cases match?

Regards,
Shawn
--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
NotGiven
Guest
 
Posts: n/a
#3: Jul 17 '05

re: require file is causing error


I changed the cuntion and it's working now. Thanks for this and other
posting for second calculaiton!


"Shawn Wilson" <shawn@glassgiant.com> wrote in message
news:40055384.DE94E2EC@glassgiant.com...[color=blue]
> NotGiven wrote:[color=green]
> >
> > I have a function in a file called tCalc.php, here's the content:
> >
> > <?php
> > function calcElapsedTime($time)
> > { // calculate elapsed time (in seconds!)
> > $diff = time()-$time;
> > $daysDiff = floor($diff/60/60/24);
> > $diff -= $daysDiff*60*60*24;
> > $hrsDiff = floor($diff/60/60);
> > $diff -= $hrsDiff*60*60;
> > $minsDiff = floor($diff/60);
> > $diff -= $minsDiff*60;
> > $secsDiff = $diff;
> > return ('(elapsed time '.$daysDiff.'d '.$hrsDiff.'h[/color][/color]
'.$minsDiff.'m[color=blue][color=green]
> > '.$secsDiff.'s)');
> > }
> > ?>
> >
> > The function works fine when in the page2.php. But when I take it out[/color][/color]
and[color=blue][color=green]
> > add this line, it doesn't process:
> > require_once('tCalc.php');
> >
> > tCalc.php is in the same directory as page2.php.
> >
> > Why is it not working?[/color]
>
> Are you getting an error? If not, put error_reporting(E_ALL); on the[/color]
first line[color=blue]
> of page2.php.
>
> Are you requiring the page before you're calling the function? Are you[/color]
sure[color=blue]
> your cases match?
>
> Regards,
> Shawn
> --
> Shawn Wilson
> shawn@glassgiant.com
> http://www.glassgiant.com
>
> I have a spam filter. Please include "PHP" in the
> subject line to ensure I'll get your message.[/color]


Closed Thread