$sanitizer->pageName() method

Sanitize as a ProcessWire page name

  • Page names by default support lowercase ASCII letters, digits, underscore, hyphen and period.

  • Because page names are often generated from a UTF-8 title, UTF-8 to ASCII conversion will take place when $beautify is enabled.

  • You may optionally omit the $beautify and/or $maxLength arguments and substitute the $options array instead.

  • When substituted, the beautify and maxLength options can be specified in $options as well.

  • If $config->pageNameCharset is "UTF8" then non-ASCII page names will be converted to punycode ("xn-") ASCII page names, rather than converted, regardless of $beautify setting.

Example

$test = "Hello world!";
echo $sanitizer->pageName($test, true); // outputs: hello-world

Usage

// basic usage
$string = $sanitizer->pageName(string $value);

// usage with all arguments
$string = $sanitizer->pageName(string $value, $beautify = false, $maxLength = 128, array $options = []);

Arguments

NameType(s)Description
valuestring

Value to sanitize as a page name

beautify (optional)bool, int, array

This argument accepts a few different possible values (default=false):

  • true (boolean): Make it pretty. Use this when using a pageName for the first time.
  • $options (array): You can optionally specify the $options array for this argument instead.
  • Sanitizer::translate (constant): This will make it translate non-ASCII letters based on InputfieldPageName module config settings.
  • Sanitizer::toAscii (constant): Convert UTF-8 characters to punycode ASCII.
  • Sanitizer::toUTF8 (constant): Convert punycode ASCII to UTF-8.
  • Sanitizer::okUTF8 (constant): Allow UTF-8 characters to appear in path (implied if $config->pageNameCharset is 'UTF8').
maxLength (optional)int, array

Maximum number of characters allowed in the name. You may also specify the $options array for this argument instead.

options (optional)array

Array of options to modify default behavior. See Sanitizer::name() method for available options.

Return value

string

See Also


$sanitizer methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #522
    In the 522nd issue of ProcessWire Weekly we'll check out the latest core updates, introduce a new module called File Mover, and more. Read on!
    Weekly.pw / 11 May 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK