[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]
Hello all Gordon - I'd like to send you many many thanks. You were so so right. It's transformed my working experience. That is with the "command line" hint/lead/pointer. It's seconds per step building up the code. You'll be knowing - in emacs its "ESC-! php myscr.php arg1 arg2 ..." with the output showing in a shell output buffer. Else a shell buffer when need to see through a lot of output. The PHP scripted page which was my "this learning exercise" goal - I got there this early afternoon. Seen http://weldsmith.co.uk/cgi_my/degdeci2dms/230719_degdeci2dms.html The PHP code is as follows... (appended) Best wishes, Rich Smith ---------------------------------------------------------------- <!DOCTYPE html> <html> <head> <title>Deg-deci to DMS</title> <link rel="stylesheet" href="/stylesheets/html_std.css" type="text/css"> </head> <body bgcolor=#FFFFFF> <h2>Degrees-deci to DMS convert</h2> <?php function val60x ($the_val) {return $the_val * 60;} function fractpart ($the_float) {return fmod($the_float, 1);} function coords_nums_valid_q ($tlat_degdeci, $tlong_degdeci) { if (!is_numeric($tlat_degdeci) || !is_numeric($tlong_degdeci)) { exit("Input must be comma-separated valid numbers"); } // echo nl2br($the_postarg); echo "DEBUG : a1=$tlat_degdeci, a2= $tlong_degdeci"; // DEBUG if ($tlat_degdeci<-90 || $tlat_degdeci>90 || $tlong_degdeci<-180 || $tlong_degdeci>180) { exit("Input error : Latitude in range -90 to +90; Longitude in range -180 to +180"); } } function dd2dms ($abs_coord_deci) { if($abs_coord_deci<0){ exit("PRG ERROR dd2dms : passed a minus number"); } $absdegs=floor($abs_coord_deci); $coord_mins=floor(val60x(fractpart($abs_coord_deci))); $coord_secs=val60x(fractpart(val60x(fractpart($abs_coord_deci)))); return array($absdegs, $coord_mins, $coord_secs); } function prettyprint_dms_lat ($pdeg, $pmin, $psec, $pdirn) { printf("%02d° %02d' %04.1f\" %s", $pdeg, $pmin, $psec, $pdirn); } function prettyprint_dms_long ($pdeg, $pmin, $psec, $pdirn) { printf("%03d° %02d' %04.1f\" %s", $pdeg, $pmin, $psec, $pdirn); } ?> <?php // shouldn't do anything during cmdline dev. if(isset($_POST['submit'])){ if(strlen($_POST['degdeci_lat_long'])>64) { exit("infeasible form bytesize"); } $the_postarg = filter_var($_POST['degdeci_lat_long'], FILTER_SANITIZE_STRING); list($lat_degdeci, $long_degdeci) = explode(',', str_replace(' ', '', $the_postarg)); coords_nums_valid_q($lat_degdeci, $long_degdeci); } ?> <?php list($latdeg, $latmin, $latsec) = dd2dms(abs($lat_degdeci)); if($lat_degdeci<0){$latsymb="S";} else {$latsymb="N";} list($longdeg, $longmin, $longsec) = dd2dms(abs($long_degdeci)); if($long_degdeci<0){$longsymb="W";} else {$longsymb="E";} ?> <?php // exit("DEBUG exit"); ?> <?php // DEBUG crude print in DMS /* echo "Lat : $latdeg Deg $latmin Min $latsec Sec $latsymb\n"; echo "Long : $longdeg Deg $longmin Min $longsec Sec $longsymb\n"; */ ?> <p> Submitted into form box: <br> <texttt> <?php { echo $the_postarg; } ?> </texttt> </p> <p> Interpretted as: <br> <texttt> <?php echo "Latitude = $lat_degdeci, Longitude = $long_degdeci"; ?> </texttt> </p> <p> Converts to: <br> <texttt> <?php prettyprint_dms_lat($latdeg, $latmin, $latsec, $latsymb); echo "   "; prettyprint_dms_long($longdeg, $longmin, $longsec, $longsymb); ?> </texttt> </p> <br> <p> Reminder - this is <b>only</b> a conversion of a set of coordinates expressed in one notation to another notation. </p> <p> (a common error were the converted coordinates applied to plot a position on a map or chart would be that, reading from "Google Maps" which uses the "WGS84" datum system, the map or chart uses another geodetic datum system) </p> <p><br><br><small> (R. Smith, 19Jul2023) </small></p> </body></html> > 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/