php overwriting specific text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gelatine1
Forum Newbie
Posts: 5
Joined: Fri May 04, 2012 2:15 pm

php overwriting specific text

Post 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 ?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php overwriting specific text

Post 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.
gelatine1
Forum Newbie
Posts: 5
Joined: Fri May 04, 2012 2:15 pm

Re: php overwriting specific text

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php overwriting specific text

Post by Celauran »

No. Like I said, this is a job for JavaScript, not PHP.
gelatine1
Forum Newbie
Posts: 5
Joined: Fri May 04, 2012 2:15 pm

Re: php overwriting specific text

Post by gelatine1 »

and if i combine something like i did above is it possible then since that is using javascript?
gelatine1
Forum Newbie
Posts: 5
Joined: Fri May 04, 2012 2:15 pm

Re: php overwriting specific text

Post by gelatine1 »

and if i combine something like i did above is it possible then since that is using javascript?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php overwriting specific text

Post by Celauran »

Doesn't really make sense to do so when you could just make use of JavaScript's Date object.
gelatine1
Forum Newbie
Posts: 5
Joined: Fri May 04, 2012 2:15 pm

Re: php overwriting specific text

Post 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
Post Reply