Abstract class Phalcon\Text

Source on GitHub

Provides utilities to work with texts

Constants

integer RANDOM_ALNUM

integer RANDOM_ALPHA

integer RANDOM_HEXDEC

integer RANDOM_NUMERIC

integer RANDOM_NOZERO

Methods

public static camelize (mixed $str, [mixed $delimiter])

Converts strings to camelize style

  1. <?php
  2. echo Phalcon\Text::camelize("coco_bongo"); // CocoBongo
  3. echo Phalcon\Text::camelize("co_co-bon_go", "-"); // Co_coBon_go
  4. echo Phalcon\Text::camelize("co_co-bon_go", "_-"); // CoCoBonGo

public static uncamelize (mixed $str, [mixed $delimiter])

Uncamelize strings which are camelized

  1. <?php
  2. echo Phalcon\Text::uncamelize("CocoBongo"); // coco_bongo
  3. echo Phalcon\Text::uncamelize("CocoBongo", "-"); // coco-bongo

public static increment (mixed $str, [mixed $separator])

Adds a number to a string or increment that number if it already is defined

  1. <?php
  2. echo Phalcon\Text::increment("a"); // "a_1"
  3. echo Phalcon\Text::increment("a_1"); // "a_2"

public static random ([mixed $type], [mixed $length])

Generates a random string based on the given type. Type is one of the RANDOM_* constants

  1. <?php
  2. // "aloiwkqz"
  3. echo Phalcon\Text::random(
  4. Phalcon\Text::RANDOM_ALNUM
  5. );

public static startsWith (mixed $str, mixed $start, [mixed $ignoreCase])

Check if a string starts with a given string

  1. <?php
  2. echo Phalcon\Text::startsWith("Hello", "He"); // true
  3. echo Phalcon\Text::startsWith("Hello", "he", false); // false
  4. echo Phalcon\Text::startsWith("Hello", "he"); // true

public static endsWith (mixed $str, mixed $end, [mixed $ignoreCase])

Check if a string ends with a given string

  1. <?php
  2. echo Phalcon\Text::endsWith("Hello", "llo"); // true
  3. echo Phalcon\Text::endsWith("Hello", "LLO", false); // false
  4. echo Phalcon\Text::endsWith("Hello", "LLO"); // true

public static lower (mixed $str, [mixed $encoding])

Lowercases a string, this function makes use of the mbstring extension if available

  1. <?php
  2. echo Phalcon\Text::lower("HELLO"); // hello

public static upper (mixed $str, [mixed $encoding])

Uppercases a string, this function makes use of the mbstring extension if available

  1. <?php
  2. echo Phalcon\Text::upper("hello"); // HELLO

public static reduceSlashes (mixed $str)

Reduces multiple slashes in a string to single slashes

  1. <?php
  2. echo Phalcon\Text::reduceSlashes("foo//bar/baz"); // foo/bar/baz
  3. echo Phalcon\Text::reduceSlashes("http://foo.bar///baz/buz"); // http://foo.bar/baz/buz

public static concat ()

Concatenates strings using the separator only once without duplication in places concatenation

  1. <?php
  2. $str = Phalcon\Text::concat(
  3. "/",
  4. "/tmp/",
  5. "/folder_1/",
  6. "/folder_2",
  7. "folder_3/"
  8. );
  9. // /tmp/folder_1/folder_2/folder_3/
  10. echo $str;

public static dynamic (mixed $text, [mixed $leftDelimiter], [mixed $rightDelimiter], [mixed $separator])

Generates random text in accordance with the template

  1. <?php
  2. // Hi my name is a Bob
  3. echo Phalcon\Text::dynamic("{Hi|Hello}, my name is a {Bob|Mark|Jon}!");
  4. // Hi my name is a Jon
  5. echo Phalcon\Text::dynamic("{Hi|Hello}, my name is a {Bob|Mark|Jon}!");
  6. // Hello my name is a Bob
  7. echo Phalcon\Text::dynamic("{Hi|Hello}, my name is a {Bob|Mark|Jon}!");
  8. // Hello my name is a Zyxep
  9. echo Phalcon\Text::dynamic("[Hi/Hello], my name is a [Zyxep/Mark]!", "[", "]", "/");

public static underscore (mixed $text)

Makes a phrase underscored instead of spaced

  1. <?php
  2. echo Phalcon\Text::underscore("look behind"); // "look_behind"
  3. echo Phalcon\Text::underscore("Awesome Phalcon"); // "Awesome_Phalcon"

public static humanize (mixed $text)

Makes an underscored or dashed phrase human-readable

  1. <?php
  2. echo Phalcon\Text::humanize("start-a-horse"); // "start a horse"
  3. echo Phalcon\Text::humanize("five_cats"); // "five cats"