String
Handle strings values
Handle strings values
Show only values that have valid value in it:
$txt = $this->get('string')
->setDelimiter('<br/>')
->add('Order date: ', $Order->date)
->add('Reference: ', $Order->customer_reference)
->add('Total amount: ', $Order->total);
Add values with delimiter
$txt = $this->get('string')
->setDelimiter(',')
->add($value1)
->add($value2);
-->
1001,1002
--> If value1 is empty:
1002
Add value with prefix:
$txt = $this->get('string',$title)
->add(': ',$text);
-->
Title: text
--> If $text is empty:
Title
Add $text with prefix+suffix, if $text has value.
$txt = $this->get('string',$title)
->add(' (',$text,')');
-->
Title (text)
--> If $text is empty:
Title
Add multiple value with delimiter
$txt = $this->get('string')
->add($title,': ',$text);
-->
Title: text
--> If $title or $text is empty:
[empty]
Add text if first argument is TRUE:
{$txt = $this->get('string',$title)
->addIf($showText,': ',$text);
-->
Title: Text
--> If $showText empty/false OR $text is empty:
Title
Add $text with delimiter, if $text has a value.
$txt = $this->get('string',$title)
->prepend($text,': ');
-->
Text: Title
--> If $text is empty:
Title
Add $text with delimiter in beginning of the string, if $text has a value.
$txt = $this->get('string',$title)
->prependIf($text,'Title for %s is: ');
-->
Title for Text is: Title
--> If $text is empty:
Title
Wrap title with H1 -tag
$txt = $this->get('string',$title)
->wrap('<h1>','</h1>');
-->
<h1>Title</h1>
--> If $title is empty:
Add A -tag, if $url has a value
$txt = $this->get('string',$title)
->wrapIf($url,'<a href="%s">','</a>');
-->
<a href='url'>Title</a>
--> If $text is empty:
Title
Class is chainable. ie. all methods that returns 'this' can be written in chain.
Method | Return | Description |
---|---|---|
setDelimiter($string) | this | String to add between different content segments on render. |
setPrefix($string) | this | String to add before content on render, if it has content. |
setSuffix($string) | this | String to add after content on render, if it has content. |
setWrap($string) | this | String to add before/after on render, if it has content. |
add($string,...) | this | Add arguments, if ALL arguments have a value. |
addIf($string,$string,...) | this | Add arguments, if FIRST has value. %s in other arguments will be replaced with first argument. |
prepend($string,...) | this | Add arguments in beginning, if ALL arguments have a value. |
prependIf($string,$string,...) | this | Add arguments in beginning, if FIRST argument has a value. %s in other arguments will be replaced with first argument. |
wrap($string,$string) | this | Add content before and after |
wrapIf($string,$string,$string) | this | Add content before and after, IF first argument is not empty. %s in other arguments will be replaced with first argument. |
getContent() | string | Content without prefix/suffix. |
render() | string | Final string content. |
__toString() | string | Final string content. |
Method | Return | Description |
---|---|---|
startsWith($needle) | bool | Return TRUE if string starts with needle. Case insensitive. |
endsWith($needle) | bool | Return TRUE if string ends with needle. Case insensitive. |
Helper Method | Return | Description |
---|---|---|
::parseStringValues($str) | array | Extract all unique string values from given string. |
::getTextBetween($str,$startText,$endText) | string | Search first occurence on start and get text untill end. Can be used foreaxample to find single value form large xml. |
::insertSeparator($str,$char,$step,$align='left') | string | Insert given char in given str in every n:th char. |
::cleanHtmlCode($str) | string | Indent HTML code according to DOM structure. |