Click to See Complete Forum and Search --> : Php


vinoth
05-02-2003, 02:51 AM
I have A php Server Running.

How To Run Php Scripts In Html And Javascripts

Norman Graham
05-02-2003, 03:04 AM
Hi Vinoth

Depends what you want to do. To insert PHP into a file, just use the <?php ?> tags to enclose all PHP code. The file MUST be called something.php to be parsed as PHP by the web server and should include the usual HTML DOCTYPE headers, title etc and close with </body> and </html>. I use PHP to call these headers and footers automatically. I use XHTML standards.

Any HTML or JS in a PHP file will also be parsed correctly. You can either insert it within PHP using the print() or echo() statements and escaping reserved characters using \, or, if your chunk of HTML/JS is too long for that, just jump out of PHP and back into HTML by closing the PHP section with the ?> tag. You can jump backwards and forwards as much as you like.

You can insert JS in PHP, but the other way round is more difficult. Officially it's impossible since JS is client side and PHP is server side, but I believe there are workarounds. I suggest you don't do it at all - stick to putting JS in PHP if required.

Any more Qs? I also recommend http://www.phpbuilder.com, which is run by the same company as this forum.

Best of luck

Norman :)

pyro
05-02-2003, 07:44 AM
Originally posted by Norman Graham
but the other way round is more difficult...but I believe there are workarounds.There are a few ways to do it. One is via the query string, which you can the parse off with PHP, another is via a form (can be hidden) which can be submitted to you PHP page (or the some PHP on the same page) and you can parse the data with that...

AdamGundry
05-04-2003, 03:35 PM
Pyro, are you saying one could submit PHP code via GET or POST, which would then be parsed? Isn't that a tremendous security risk? Or have I interpreted you wrongly?

Adam

pyro
05-04-2003, 11:57 PM
No, all that I ment was that you could pass values to a PHP page via those two methods. So, say your javascript detects the screen res, you could then pass this info to your PHP page via the methods listed above.

AdamGundry
05-05-2003, 03:08 AM
Oh, I see. Thanks, Pyro.

Adam