D&C GLug - Home Page

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

[LUG]Re: PHP working environment - easy development

 

Oh **** how could I have been so dim... Aaghhh...
There is a PHP installed on my 10 year old Mac

bash-3.2$ which php
/usr/bin/php


tested...

-------- 230718_test_php_at_cmdline.txt --------

Everything else...

<?php
$myout = 9 * 7;
echo $myout;
?>

And more else...

------------------------------------------------

> php 230718_test_php_at_cmdline.txt

v

"
Everything else...

63
And more else...
"

----------------------------------------------------------------

Reason not to work alone - the well of sense in an abyss of stupidity.

Yes I would have only had to change the "initial" code of the ilk of

"
if(isset($_POST['submit'])){
  if( (strlen($_POST['lat_deci'])>64) OR (strlen($_POST['long_deci'])>64) ){
     exit("infeasible form bytesize");
  }
  ...
  $lat_degdeci = $_POST['lat_deci'];
  $long_degdeci = $_POST['long_deci'];
"

to somethink like 

"
  $lat_degdeci = WTF_YOU_WANT_TO_TEST
  $long_degdeci = WTF_IS_OTHER_PART_OF_TEST
"

and it would "fire-up" and work at the command-line.

You could set up a whole suites of functions which are probed with
real and malicious variables so that when getting it onto the
webserver you have a foundation of known good code to tie-in the
remaining functionality to.

Thanks so much

Rich S


> On 18 Jul 2023, at 12:10, Gordon Henderson <gordon+lug@xxxxxxxxxx> wrote:
> 
> 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/

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