Using Strings-Verifying Strings

Is String Numeric Is String A Date Time Is String Within An Array Of Strings Check Entered Web Address This isn’t right – the first test rejects doamins with a hyphen in them Verify Email Address A thorough version from this article here  

Read More

Differences To C and C++

=== and !=== PHP is a loosly typed language.  For instance this is true because PHP converts to the requried types before the compare: if (1000 == “+1000”) To perform an exact comparison you can use this instead, which is false if (1000 === “+1000”) For does not equal you can also use !== Break […]

Read More

Convert Strings

Converting to HTML, from form POST, etc See here Converting String To Variable You don’t need to, but if you want to force to a particular type you can: Converting Variables To String No need, PHP automatically converts a varaible to the type needed for the context being used If you want to: Convert copy […]

Read More

Sanitising & encoding strings

Sanitising for HTML Convert special HTML entities back to characters URL Encode and Decode Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. A space is encoded to %20 in URLs, and to + […]

Read More

Built In Superglobal Variables

Warning When Using Superglobal Variables Hackers often use these to try and inject code etc.  When accessing superglobal variables ensure you sanitise them.  E.g. $CameFromPage = htmlentities($_SERVER[‘HTTP_REFERER’]); //htmlentities() converts things like < > ” \ etc into HTML strings like &lt; so they become harmless. Superglobal Variables Always available in all scopes $GLOBALS References all […]

Read More

Print vs Echo

Print is a PHP function called with an argument.  Echo is a PHP language construct.  Echo is therefore faster, but when you need an actual function call you can use print.  For example this only wotks using print: $MyVariable ? print “True” : print “False”;

Read More

Constants

Constants define (“MY_ROOT_PATH”, “/usr/local/httpdocs/”); Then to use $PathToUse = MY_ROOT_PATH; PHP Magic Constants __LINE__ The current line number of the file. __FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved […]

Read More