arrays - php timed (duration) display -


so want have array in .txt file separate lines , pull each line , display after duration... don't know if need mix ajax php or if can straight php.

is foreach best way this?

<?php      $x=file("sayings.txt");     foreach ($x $value)       {       echo $value . "<br />";       }     ?>  

where can implement duration.. there wait?

like this:

{ echo $value . "
"; wait 1000 //miliseconds }

went javascript one.. here if want answer/code: javascript array timed

service side solution

server side :

<?php  $x=file("sayings.txt"); foreach ($x $value) {     echo $value . "<br />";//send output     flush();               //make sure it's outputted     sleep(1);              //sleep 1 second } ?>  

client side solution

but, can use ajax call parameter (an index) return next index every call. can settimeout in javascript.

<script type="text/javascript"> var arrayindex = 0; function getarraydata() {     var datafromserver="";     $.get("myserverpage.php", { 'arrayindex': arrayindex },          function(data){          alert("line : " + data);          arrayindex++;          var t=settimeout("getarraydata()",1000);//every 1 second      });  } </script> 

in myserverpage.php have check $_get check index , output line. (validate if array index ok). also, in server side, once have finish find array not can trigger stop , need return data client (instead of line) , tell javascript stop. that's it. hope you.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -