Page 1 of 1

php overwriting specific text

Posted: Fri May 04, 2012 2:18 pm
by gelatine1
hello,
i need some function that keeps editing my html code. if i do it with a loop and echo or print it just places all the stuff under each other and i want them to overwrite it.
i've tried to to something like this
<script type="text/javascript">
function looptext() {
document.getElementsByTagName('p')[0].innerHTML="

Code: Select all

<?php echo date('s'); ?>
";
t=setTimeout("looptext()",1000);
}
</script>

but that didn't work because it calculated date('s') once and then just looped that second so i need to do something like this totally in php so i will need a way to overwrite text on a specific place like document.getElementsByTagName('p')[0].innerHTML and something like setTimeout.can someone help me with that ?

Re: php overwriting specific text

Posted: Fri May 04, 2012 2:34 pm
by Celauran
If I'm understanding you correctly, this isn't something you can do in PHP due to its server-side nature. Use JavaScript instead.

Re: php overwriting specific text

Posted: Fri May 04, 2012 2:51 pm
by gelatine1
so theres no possibility to loop for example 1,2,3,4,5,6,7,8,9,10 in exactly 10 seconds and everytime on the same line?

Re: php overwriting specific text

Posted: Fri May 04, 2012 2:56 pm
by Celauran
No. Like I said, this is a job for JavaScript, not PHP.

Re: php overwriting specific text

Posted: Fri May 04, 2012 3:01 pm
by gelatine1
and if i combine something like i did above is it possible then since that is using javascript?

Re: php overwriting specific text

Posted: Fri May 04, 2012 3:02 pm
by gelatine1
and if i combine something like i did above is it possible then since that is using javascript?

Re: php overwriting specific text

Posted: Fri May 04, 2012 3:03 pm
by Celauran
Doesn't really make sense to do so when you could just make use of JavaScript's Date object.

Re: php overwriting specific text

Posted: Fri May 04, 2012 3:10 pm
by gelatine1
because it is for school and i have to use php for the date
but i just wanted to make it nice by that