So I want to have an array in a .txt file with separate lines and pull each line and display it after a certain duration… I don’t know if I need to mix ajax with php or if this can just be straight php.
Is foreach the best way to do this?
<?php
$x=file("sayings.txt");
foreach ($x as $value)
{
echo $value . "<br />";
}
?>
Where can I implement a duration.. is there a wait?
like this:
{
echo $value . “
“;
wait 1000 //miliseconds
}
Went with javascript for this one.. its here if you want the answer/code:
javascript array timed
Service side solution
Server side you could do this :
Client side solution
But, you can also use Ajax call with a parameter (an index) that will return the next index every call. You can do that with a
SetTimeOutin Javascript.In myServerPage.php you just have to check the $_GET to check the index and to output the good line. (Validate if the array index is ok). Also, in the server side, once you have finish find that the array is not good this can be the trigger to stop and you just need to return a data to the client (instead of just the line) and will tell the javascript to stop. That’s it. Hope it help you.