PLZ: A handy PHP library for lazy programmers
  • Namespace
  • Class
  • Tree
  • Todo

Namespaces

  • amekusa
    • plz
  • PHP

Classes

  • alt
  • arr
  • constant
  • dom
  • fn
  • num
  • obj
  • op
  • path
  • str
  • sys
  • T
  • type
  • xml

Exceptions

  • ErrorException

Class str

String utilities

To get started, place the following line around top of your code.

use amekusa\plz\str;
Abstract
Namespace: amekusa\plz
Located at str.php

Methods summary

public static boolean
# eq( string $X, string $Y, boolean $CaseInsensitive = false )

Returns whether $X equals $Y

Returns whether $X equals $Y

Parameters

$X
A string to compare with $Y
$Y
A string to compare with $X
$CaseInsensitive
(optional) Whether or not to ignore letter case

Returns

boolean

Example

Demonstration

$var1 = 'ABC';
$var2 = 'ABC';
$var3 = 'Abc';
var_dump( str::eq($var1, $var2)       );
var_dump( str::eq($var1, $var3)       );
var_dump( str::eq($var1, $var3, true) ); // Case-insensitive
bool(true)
bool(false)
bool(true)

public static boolean
# is_visible( string $X )

Returns whether $X contains any visible character

Returns whether $X contains any visible character

Parameters

$X

Returns

boolean

Example

Demonstration

$var1 = " \t \n ";   // Spaces, Tab, Linebreak
$var2 = " \t \n _ "; // Spaces, Tab, Linebreak, and Underscore
var_dump( str::is_visible($var1) );
var_dump( str::is_visible($var2) );
bool(false)
bool(true)

public static boolean
# is_mb( string $X )

Returns whether $X contains any multibyte character

Returns whether $X contains any multibyte character

Parameters

$X

Returns

boolean

Example

Demonstration

$var1 = "ABC 123";
$var2 = "ABC 一二三";
var_dump( str::is_mb($var1) );
var_dump( str::is_mb($var2) );
bool(false)
bool(true)

public static boolean
# contains( string $X, string $Y, boolean $CaseInsensitive = false )

Returns whether $X contains $Y

Returns whether $X contains $Y

Parameters

$X
A haystack
$Y
A needle
$CaseInsensitive
(optional) Whether or not to ignore letter case

Returns

boolean

Example

Demonstration

$haystack = "ABCDEFGHI";
$needle1  = "DEF";
$needle2  = "Def";
var_dump( str::contains($haystack, $needle1)       );
var_dump( str::contains($haystack, $needle2)       );
var_dump( str::contains($haystack, $needle2, true) ); // Case-insensitive
bool(true)
bool(false)
bool(true)

public static string
# trim( string $X )

Removes control characters in $X

Removes control characters in $X

Parameters

$X

Returns

string
A processed string
public static string
# replace_nl( string $X, string $With = '' )

Replaces newline characters in $X with the supplied string

Replaces newline characters in $X with the supplied string

Parameters

$X
A haystack
$With
(optional) A replacement string

Returns

string
A processed string

Example

Replacing every line-breaks with <br>\n

$var = <<<TEXT
If the doors of perception were cleansed
every thing would appear to man as it is,
Infinite.
TEXT;
echo str::replace_nl($var, "<br>\n");
If the doors of perception were cleansed<br>
every thing would appear to man as it is,<br>
Infinite.

public static
# repeat( string $X, integer $Times = 2, string $Insert = '' )

Repeats $X

Repeats $X

Parameters

$X
A string to repeat
$Times
(optional) How many times $X to appear
$Insert
(optional) A string to insert after every repetition

Example

Demonstration

echo str::repeat('Knock');
KnockKnock

Repeating so many times

echo 'YEA'.str::repeat('H', 32).'!!';
YEAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!

PLZ: A handy PHP library for lazy programmers API documentation generated by ApiGen