JB-Template for PHP7 - created out of frustration!

To test user’s PHP scripts I usually copy and paste from the forum then proceed to find the utilities and extras which make testing so much easier. Problem is there are quite a few script blocks so I decided to create a test-001.php file that includes all the goodies from a JB-TEMPLATE.php template:

file: test-001.php

<?php
  declare(strict_types=1);

  $title = 'JUST TESTING';

  # icons available when using FireFox Addon "marc gueury"
  # http://users.skynet.be/mgueury/mozilla/

  # 18 DOCTYPES AVAILABLE
  # defaults to STRICT - doctype=5
  # 1..5 all have GREEN ICON 
  # 6 = HTML5 - HAS WARNNGS
  $doctype = 5; 

  require $_SERVER['DOCUMENT_ROOT'] .'/JB-TEMPLATE.php';
?>
</head>  
<body>
  <div>
    <h1> <?= $title ?> </h1>
    <?php fred( $info, '$info'); ?>
  </div>  
</body>
</html>
Output

file: /localhost/JB-TEMPLATE.php (makes it easier to call from any other other directory)
<?php 
# START usage on your test page
  declare(strict_types=1);

  $doctype = $doctype ?? 5;
  $info = info();

# RECOMMENDED FIREFOX HTML VALIDATOR EXTENSION
  # Search for: # marc gueury  

# ERROR STUFF
  error_reporting(-1); 
  ini_set('display_errors', '1');
  ini_set('display_startup_errors', '1');

# show line feed in html source otherwise all text is a single line
  defined('NNN') ?: define('NNN', "\n"); 

  echo getDoctype($doctype);
  echo NNN;

?><html lang="en">

<head>
<title> <?= $title ?> </title>

<style type="text/css">
body {background-color: #fafafa; margin:0; padding:0;}
.bd0 {border:0;} .bd1 {border:solid 1px #060;}
.bgs {background-color:snow;} .bge {background-color:#eee;}
.bgy {background-color:#ff0;} .bgl {background-color:#dfd;}
.clr {color: #f00;} .clg {color: #0f0;}
.clb {clear: both;}
.fs2 {font-size: 2.00em;}
.fwb {font-weight: 700;}
.hhh {display: none;}
.mga {margin:  0 auto;} .mg1 {margin:1em auto;}
.p42 {padding: 0.42em;}
.tac {text-align: center;} .tal {text-align:left;} .tar {text-align:right}
.w42 {width: 42%; max-width: 420px;}
.w88 {width: 88%; max-width: 888px;}
</style>


<?php 
//============================================================
function fred( $val='NO PARAMETER???', $title='')
{
  echo NNN;
  echo '<div class="w88 mg1 bgl bd1 p42">';
  echo NNN;
    echo 'function fred($val, $title)';
    echo '<hr>';
  echo NNN;
    echo '$val &nbsp;==> ' .gettype($val);
  echo NNN;
    echo '<br>';
  echo NNN;
    echo '$title ==> ' .$title;
  echo NNN;
    echo '<hr>';
  echo NNN;
      echo '<pre>'; 
        print_r( $val ); 
      echo '</pre>';
  echo NNN;
   echo '</div>';   
  echo NNN;
}///

//==================================================================================
function getDoctype($val=5)
{
# doctypeS - https://www.w3.org/QA/2002/04/valid-dtd-list.html
# PROBLEMS - SHOW AMBER WARNING AND NOT GREEN ICON
  $doctypes = [
  0 => '<!doctype HTML>',
  1 => '<!doctype html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
  2 => '<!doctype html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
  3 => '<!doctype math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">',
  4 => '<!doctype html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
# GOOD  - ALL SHOW GREEN ICON
  5 => '<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
  6 => '<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">',
  7 => '<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
  8 => '<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
  9 => '<!doctype html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
  10=> '<!doctype math PUBLIC "-//W3C//DTD MathML 2.0//EN"  "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
  11=> '<!doctype html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
  12=> '<!doctype svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
  13=> '<!doctype svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
  14=> '<!doctype svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
  15=> '<!doctype svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN"  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">',
  16=> '<!doctype svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">',
  17=> '<!doctype html PUBLIC "-//IETF//DTD HTML 2.0//EN">',
  18=> '<!doctype html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
  ];

$val = min($val, 18);

return $doctypes[$val];
}///

function info()
{
$result = <<< ____TMP

   <b class="fs2">Installation:</b>
   Create the following test.php file: 

&lt;php 
  declare(strict_types=1);

  # GET/SET \$title
    \$title = \$title ?? 'JB-TEMPLATE.php';

  # GET/SET doctype - defaults to doctype ... STRICT
    \$doctype = \$doctype ?? 5; // 18 available

  # REMOVE REMARK   
    # require \$\_SERVER['DOCUMENT_ROOT'] ./JB-TEMPLATE.php';

  # IF AND ONLY IF REQUIRED ADD EXTRA STUFF IN &lt;head&gt; 
  # OTHERWISE   
?&gt;
  &lt;head&gt;
  &lt;body&gt;

  &lt;php 
    # PHP STUFF GOES HERE 
    # instead of echo \$variable;
    # try this: 
      fred( \$variable, \$title='is optional' ); 
      # \$variable can be boolean, integer, float, string, array or object
  ?&gt;

  &lt;body&gt;
  &lt;html&gt;

____TMP;

return $result;
}
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.