Monday, June 28, 2010

Magical Typesetting in PHP

So, well working for Route 50
I came up with a fantastic idea for “typesetting” that well exceeded the norm.  Something we constantly have
issues with is what type of string was sent to MySQL originally (some of us have different conventional
ideas about where escaping HTML should be located.) as well as outputting that string in its correct format.

with my fantastic idea, came up with a couple variables classes that I put in a file named href="">class_typesetting.php.  The version on gist.github is
slightly modified from the original version on the server.

It creates three classes,
GenericVariable, String, and Number.  So far we haven’t used GenericVariable, but since the introduction of
the classes I’ve taken it upon myself to introduce them to any new code I write.  When we create Core v5
(which will Objectify everything) strings taken from SQL will automatically be re-stored as String class

First, lets examine some useful functionality.
$title = new String($_POST[“title”]); // <strong>Hello
HTML Output: <?= $title->html ?>
(&lt;strong&gt;Hello 'World'&lt;/strong&gt;)
Text Output: <?=
$title->text ?> (Hello 'World')
SQL Output: <?= $title->sql ?>
(<strong>Hello \'World\'</strong>)
HTML Attribute Output: <?=
$title->html_attr ?>(&lt;strong&gt;Hello &#039;World&#039;&lt;/strong&gt;)[/codesyntax]

allows for quick and easy access to the variables without having to worry about escaping them.

recommend you hit the download link (class_typesetting.php) and play around with it.  Tell me about anything
that’s not working correctly and if possible implement it in your future code.  (This means I’m putting this
code in the “Public Domain”).

1 comment:

  1. Oh this really is wonderful. Perhaps a URL class (though not really a basic datatype)
    could extend this class, and make a canonical one out of it (with the http and trailing forward slash), also
    removing javascript schemes and evil things, also making sure it's a valid-looking one with regex?
    Next I'm thinking email OvO