« HS-CMS documentation home

Guide to Working With My PHP Projects

Indentation conventions

  1. Use real tabs, not spaces, to indent. Some editors require you to enable a setting to switch this. PSPad for Windows is one such program; go to Settings > Program Settings > Editor (Part 2) and check “Real Tabs.”

  2. I try to use tabs of size 4 in all my webdev files, including PHP and Markdown, PHP files, so set your editor accordingly. (This is partly because of the next rule…)

  3. Markdown, if you use it, requires tabs or 4 spaces (and no less!) to indicate indentation.

Filename and URL conventions

  1. In public URLs, I almost always prefer hyphens (-) between words for readability and because underscores can look like spaces when underlined (e.g. in a hyperlink), which can especially confuse new Internet users.

  2. In server-side-only files and directories that will never appear in a browser address bar, I prefer underscores (_) between words.

  3. Going “up” a level in the URL should produce expected functionality!

Function use guidelines

  1. Do use multibyte (Unicode-compatible) equivalents of all the string manipulation functions (that is, those which begin “mb_”.) This means to use mb_send_mail(), mb_strlen(), mb_strpos(), mb_strrpos(), mb_substr(), mb_strtolower(), mb_strtoupper(), mb_substr_count(), mb_ereg(), mb_eregi(), mb_ereg_replace(), mb_eregi_replace(), and mb_split().

    In cases where it really doesn’t matter if the function can work with multibyte strings, then there is no need to use the “mb_” version. Example:

    $string_is_empty = !(strlen($some_string));

    Since the above code only checks to see if 0 is returned or not, and that does not depend on the encoding used, then strlen() is fine.