Text helper


1Presentation

Helper offering several methods of handling character strings.


2filenamize()

Converts text into a string that can be used as a file name.

Method signature:

filenamize(string $filename, bool $hyphenSpaces=true, bool $lowercase=true) : string

Parameters:

  • $filename: Text to convert.
  • $hyphenSpaces: true to replace spaces with dashes.
  • $lowercase: true to make text all lowercase.

Return value: The file name.


3urlize()

Converts text so that it can be used in a URL.

Method signature:

urlize(?string $txt, bool $avoidUnderscores=true) : string

Parameters:

  • $txt: Text to convert.
  • $avoidUnderscores: true to replace underscores with dashes.

Return value: The converted text.


4isValidHtmlSyntax()

This method checks whether an HTML feed is syntactically correct.

Method signature:

isValidHtmlSyntax(string $html) : bool

Parameter: The HTML stream to be validated.

Return value: true if the HTML stream is valid, false otherwise.


5htmlToText()

This method transforms an HTML stream into plain text.

Method signature:

htmlToText(string $html, bool $cleanup=false) : string

Parameters:

  • $html: HTML stream to convert.
  • $cleanup: true to remove the content of <blockquote>, <pre> and <code> tags.

Return value: Plain text generated from HTML.


6encodingCompatible()

This method indicates whether a character string encoded in UTF-8 contains only characters compatible with the encoding supplied as a parameter.

Method signature:

encodingCompatible(string $text, string $encoding) : bool

Parameters:

  • $text: The text to analyze.
  • $encoding: The encoding to use.

Return value: Return value : True if the text contains only characters compatible with the character encoding supplied in parameter.