Neuron-PHP

NString
in package

Enhanced string manipulation utility class for the Neuron framework.

This class provides a comprehensive set of string manipulation methods with an object-oriented approach, offering convenient operations for string processing, formatting, and transformation. It wraps PHP's native string functions with additional functionality and consistent behavior.

Key features:

  • String extraction methods (left, right, mid)
  • Case conversion utilities (camelCase, snake_case)
  • String formatting and cleaning operations
  • Length and position-based operations
  • Quote handling for string literals
  • Modern PHP property syntax with getter/setter
Tags
example
// String manipulation examples
$str = new NString('hello_world_example');

// Case conversions
echo $str->toPascalCase();    // 'HelloWorldExample'
echo $str->toCamelCase();     // 'helloWorldExample'
echo $str->toSnakeCase();     // 'hello_world_example'
echo $str->toUpper();         // 'HELLO_WORLD_EXAMPLE'
echo $str->toLower();         // 'hello_world_example'

// String extraction
echo $str->left(5);           // 'hello'
echo $str->right(7);          // 'example'
echo $str->mid(6, 10);        // 'world'

// String formatting
$quoted = new NString('"some text"');
echo $quoted->deQuote();      // 'some text'
echo $quoted->quote();        // '"some text"'

Table of Contents

Properties

$value  : string

Methods

__construct()  : mixed
NString constructor.
deQuote()  : string
left()  : string
length()  : int
mid()  : string
quote()  : string
right()  : string
toCamelCase()  : string
Convert string to camelCase (first letter lowercase).
toLower()  : string
Convert the string to lowercase.
toPascalCase()  : string
Convert string to PascalCase (first letter uppercase).
toSnakeCase()  : string
toUpper()  : string
Convert the string to uppercase.
trim()  : string

Properties

Methods

__construct()

NString constructor.

public __construct(string $string) : mixed
Parameters
$string : string

deQuote()

public deQuote() : string
Return values
string

left()

public left(int $length) : string
Parameters
$length : int
Return values
string

length()

public length() : int
Return values
int

mid()

public mid(int $start, int $end) : string
Parameters
$start : int
$end : int
Return values
string

quote()

public quote() : string
Return values
string

right()

public right(int $length) : string
Parameters
$length : int
Return values
string

toCamelCase()

Convert string to camelCase (first letter lowercase).

public toCamelCase() : string
Return values
string

toLower()

Convert the string to lowercase.

public toLower() : string
Return values
string

toPascalCase()

Convert string to PascalCase (first letter uppercase).

public toPascalCase() : string
Return values
string

toSnakeCase()

public toSnakeCase() : string
Return values
string

toUpper()

Convert the string to uppercase.

public toUpper() : string
Return values
string

trim()

public trim() : string
Return values
string

        
On this page

Search results