Forum Moderators: coopster

Message Too Old, No Replies

Converting Javascript to PHP

... little help please : )

         

j4mes

10:08 pm on May 17, 2004 (gmt 0)

10+ Year Member



Hi,

I am gradually trying to move away from Javascript and into PHP (good move, huh :P) but for the time being I am a complete noob to PHP, so I wondered, perhaps one of you nice people could quickly convert the following for me, or point me in the right direction if this isn't quite possible?


<script type="text/javascript">
function year() {
var time = new Date();
var year = time.getYear();
if (year < 1900) {year += 1900;}
document.write("&#169;&nbsp;&nbsp;&nbsp;<b>James Nicholson</b>&nbsp;&nbsp;&nbsp;2003 - " + year);}
</script>

...

<script type="text/javascript">year();</script>

Thanks in advance. :)

-- James.

jatar_k

10:16 pm on May 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



just put this where you want it to show up

<?php
echo "&#169;&nbsp;&nbsp;&nbsp;<b>James Nicholson</b>&nbsp;&nbsp;&nbsp;2003 - ", date [ca2.php.net]('Y');
?>

the file in which this appears must be php parsed

Birdman

10:16 pm on May 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here ya go:

<?php
print("&#169;&nbsp;&nbsp;&nbsp;<b>James Nicholson</b>&nbsp;&nbsp;&nbsp;2003 - " . date [php.net]("Y"));
?>

You're quick jatar_k!

j4mes

10:19 pm on May 17, 2004 (gmt 0)

10+ Year Member



jatar, Birdman that's fantastic, thank you.

I love how PHP gets stuff like this done with so little effort!

-- James.

[edited by: j4mes at 10:19 pm (utc) on May 17, 2004]

jatar_k

10:19 pm on May 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



;)

j4mes, notice that the 2 work exactly the same but we used echo and print.

there is never only 1 way to do something

j4mes

10:21 pm on May 17, 2004 (gmt 0)

10+ Year Member



Yeah, I noticed. Is one preferable to the other in terms of speed, etc., or is this simply (most likely!) another case of personal preference?

jatar_k

10:26 pm on May 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



mostly personal preference but ergophobe did some work on Benchmarking PHP text output [webmasterworld.com], which is in the PHP library, that is worth checking out