D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

[LUG]Re: PHP working environment - easy development

 

On Tue, 18 Jul 2023, rds_met wrote:

PHP being "inside out" as intersections in webpages (smart) seems to
have this problem of making it uniquely difficult to "fire it up" on
its own.

Am I missing something?

PHP is a general purpose programming language. It can be run from the command line like most others - you don't need to run it inside a web server/browser combo.

Simply start the file with

  <?php

and end it with

  ?>

then

  php filename

and it will run.

Anything outside those sections will be printed to the output with variables expanded as usual.

You can do the usual "shebang" trick

  #!/path/to/php
  <?php
    printf ("Hello, world!\n)
  ?>
  This also prints Hello, World!
  <?php
    printf ("1+2=%d\n", 1+2)
  >?



  chmod +x filename
  ./filename

and off you go.

Gordon
--
The Mailing List for the Devon & Cornwall LUG
FAQ: https://www.dcglug.org.uk/faq/