You are here: Re: Calling scripts « All PHP « IT news, forums, messages
Re: Calling scripts

Posted by d43m0n AT shaw DOT ca on 09/21/06 15:14

kenoli wrote:
> I'm interested in the correct way to do two things:
>
> 1. Stop executing a script and begin executing it again from the top.
> (i.e. go back to the top of the .php file you are in and start over as
> if you had called the file for the first time, realizing some variables
> may need to be reset.)
>
> 2. Stop executing a script and start executing a script in another
> .php file.
>
> I'm not sure include() is the way to do this. I am not looking to
> insert a script in an existing script but to exit one script and either
> start it over or begin executing another one. I don't want the action
> sent back to the first script at the end of the execution of the
> second. I'm not sure how an include works exactly in this respect. I
> think of it more as inserting code into some other code rather than as
> sending the action elsewhere.
>
> The only other way I can see to do this is to use the header()
> function, but this can't be done once html has been sent to the
> browser. I've never fully understood this function or understood how
> this limitation works.
>
> It is obvious how to do this when some user action is involved like a
> form action or link selection. I am talking about how to do this as an
> action from within a script where, for instance, a conditional like a
> switch or something needs to send the action to the top of the same
> script or to another .php file.
>
> --Kenoli

To execute a new script, or to reproduce the results of your script
there are many ways. First you have to determin what you want to
acomplish.

I personally am a command/terminal programmer, I like seeing my results
come through a shell, rather then preprocess through http, as in a "web
site". Now, to get to the point, the best way to look at php is like
looking at any other language. Variables are your best freind, and can
do more then just define foo=bar. To reproduce results, with previous
results, you need to use variables to its fullest. Define functions to
use multiple times or later on in your script. Too loop your script,
that means to start a funtion, and then restart the funtion from the
start to reprocess your data and reexecute the functions.

Here is an example:

<?php
$loop = NULL;
$bar = true; // Assigns the global variable $bar to the boolean value
'true', which retutrns 1.
$foo = &$bar; // Forces and destroys $bar, and transfers its value to
$foo.

while($foo) {
usleep('1000000');
echo 'Hello world' . "\n";
if (($loop++) <= 10) {
$foo = false;
}
}
?>

This code is a bit elaberate, but it has a purpose. Notice how I
defined $loop as null, and then defined $loop after the echo function,
thus causing echo to return 11 echo's, before defining $foo as false,
stoping the loop.

<?php
for ($i = '0'; $i <= '10'; $i++) {
echo 'Hello World' . "\n";
}
?>

This script is simpler, uses the for function to loop until the middle
statment returns true.

These 2 methods can be used to loop through your program, but are often
ineffecint, because the result can often be predicted.

Instead, its nice to make use OOP through php.

Lets take a look at what OOP is first. OOP, is POO spelt backwards, but
other then that its making use of a class defintion, which includes
local/private/public variables, and functions that are only accessed
fromk within the class definition.

<?php
class hello {
var $msg = 'Hello World' . "\n";
function world() {
return $this->msg . "\n";
}
}

$helloworld = new hello;
echo $helloworld->world();
?>

This is a simple example of how to create a class defintion, object
oriented variable, and returning a local variable, and echo'ing it to
the screen.

Now, OOP allows you to define many variables with the same class, but
have its own variables and same functions, "potentially" producing
differnt results.

You can create many statments after that, and even create and redefine
the varibles from within each OO variable.

Now, Read The Flipping/Flying/Fluttering Manual @ http://php.net

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация