\duncan3dc\HelpersHtml

Summary

Methods
Properties
Constants
price()
getCurrencies()
formatKey()
string()
stringLimit()
date()
textDate()
img()
entities()
time()
plural()
redirect()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

price()

price(integer|float $val, array $options) : string

Format a number as price.

$options:

  • string "class" The css class to apply to the element if the number is negative (default: "red")
  • string "currency" The currency code that the price is in (use Html::getCurrencies() to get supported currency codes)
  • string "symbol" Instead of a currency a symbol can be provided directly (default: "£")
  • string "symbolp" The same as symbol except it is added after the price, not before it
  • int "decimalPlaces" The number of decimal places the price should show (default: 2)

Parameters

integer|float $val

The number to format

array $options

An array of options (see above)

Returns

string

getCurrencies()

getCurrencies(boolean $symbols) : array

Get the currencies supported by the Html class methods.

Parameters

boolean $symbols

Whether to return a multi-dimensional array with the symbols of a currency, or just the currency codes and their names

Returns

array —

Keyed by the currency code, value depends on the $symbols parameter

formatKey()

formatKey(string $key, array $options) : string

Format a string in a human readable way.

Typically used for converting "safe" strings like "section_title" to user displayable strings like "Section Title"

$options:

  • string "underscores" Convert underscores to spaces (default: true)
  • string "ucwords" Run the string through ucwords (default: true)

Parameters

string $key

The string to format

array $options

An array of options (see above)

Returns

string

string()

string(string $string, array $options) : string

Trim a string, and return an alternative if it is falsey.

$options:

  • string "alt" The string that should be returned if the input is falsey (default: "n/a")

Parameters

string $string

The string to format

array $options

An array of options (see above)

Returns

string

stringLimit()

stringLimit(string $string, array $options) : string

Limit a string to a maximum length.

$options:

  • int "length" The maximum length that the string can be (default: 30)
  • int "extra" The extra length that is acceptable, while aiming for the above length (default: 0)
  • string "alt" The string that should be returned if the input is falsey (default: "n/a")
  • bool "words" Set to true to never break in the middle of a word (default: true)
  • string "suffix" The string that should be appended if the input has been shortened (default: "...")

Parameters

string $string

The string to limit

array $options

An array of options (see above)

Returns

string

date()

date(string $format, string|integer $date, string|integer $time, array $options) : string

Parse a date in the same way as Helper::date() except return a string on failure.

$options:

  • string "alt" The string that should be returned if Helper::date() returns 0 (default: "n/a")

Parameters

string $format

The format to apply to the date

string|integer $date

The date to parse

string|integer $time

The time to parse

array $options

An array of options (see above)

Returns

string

textDate()

textDate(string|integer $date) : string

Convert a date into a textual string described the date/time relative to now.

Parameters

string|integer $date

The date to parse

Returns

string

img()

img( $options)

Parameters

$options

entities()

entities(string $string) : string

Wrapper for htmlentities() with default options.

Identical to calling htmlentities($string, ENT_QUOTES, "UTF-8")

Parameters

string $string

The string to convert the entities from

Returns

string

time()

time(integer $seconds) : string

Take a number of seconds and convert it to the relevant units (seconds, minutes, hours, etc)

Parameters

integer $seconds

The number of seconds

Returns

string

plural()

plural(integer $int, string $word, string $plural) : string

Take an integer and a word and output it with it's appropriate plural suffix, if required

Parameters

integer $int

The number of the $word

string $word

The word

string $plural

The text to append to $word if there are multiple (or zero)

Returns

string

redirect()

redirect(string $url) : void

Send a location header.

Then kill the script, incase some output has already been output, we don't want the page to carry on outputing for security reasons.

Parameters

string $url

The url to redirect to