|
Posted by Rich on 01/30/06 21:03
In article <1jgbvulmfnf71$.1lol61gwsbjxe$.dlg@40tude.net>, Alvaro G. Vicario
says...
>
>*** Pablito escribiσ/wrote (Sun, 29 Jan 2006 15:14:44 GMT):
>> <?php
>> $cont=fopen('cont.txt','r');
>> $incr=fgets($cont);
>> //echo $incr;
>> $incr++;
>> fclose($cont);
>> $cont=fopen('cont.txt','w');
>> fwrite($cont,$incr);
>> fclose($cont);
>> echo "<script type="text/javascript">
>> var incr=$incr
>> </script>";
>> ?>
>
>This code doesn't make much sense. You must understand that PHP and
>JavaScript are _not_ executed at the same time. PHP is parsed in the server
>and it's used to create the JavaScript code. So, when you get JavaScript
>errors, check first the generated code.
>
>Try this:
>
><?php
>$cont=fopen('cont.txt','r');
>$incr=fgets($cont);
>//echo $incr;
>$incr++;
>fclose($cont);
>$cont=fopen('cont.txt','w');
>fwrite($cont,$incr);
>fclose($cont);
>?>
><script type="text/javascript"><!--
>var incr=<?=$incr?>;
>//--></script>
>
>Also, your code should raise a PHP parse error. I guess your PHP install is
>configured to hide errors. Edit php.ini and set accordingly the
>error_reporting value.
>
As you said the PHP is parsed by the server, so by the time the web browser gets
the document, it only sees the HTML and Javascript that were already present or
generated by the PHP.
Looks like Pablito was pretty close, but maybe a few syntax errors in the echo
statement. I prefer using the "<?=$var?>" method of printing in PHP variables so
I can put in less time trouble shooting syntax errors with echo. : )
Rich
--
Newsguy -- http://newsguy.com
[Back to original message]
|