Previous Next
RSIO RSValidation

RSStringUtil

Strign Utility Class

Table of Contents

Introduction

RSStringUtil is a static class. Just require it and use it!


1 <?php
2 require_once('RSStringUtil/RSStringUtil.php');
3 //will print This is my...
4 echo RSStringUtil::limit('This is my text that is too long', 10);
5 ?>

RSStringUtil::removeTrailingString

Removes the string passed as second argument from the end of the string passed as first argument and returns the result.


1 <?php
2 require_once('RSStringUtil/RSStringUtil.php');
3 //will print the path with the trailing slash removed: /my/path
4 echo RSStringUtil::removeTrailingString('/my/path/', '/');
5 ?>

RSStringUtil::removeLeadingString

Removes the string passed as second argument from the beginning of the string passed as first argument and returns the result.


1 <?php
2 require_once('RSStringUtil/RSStringUtil.php');
3 //will print $myvar.
4 echo '$' . RSStringUtil::removeLeadingString('$this->myvar', '$this->');
5 ?>

RSStringUtil::bytesToKiloBytes

Converts the number of bytes passed as argument to kilo bytes and returns the result. With the second argument you can specify the precision the default is 1.


1 <?php
2 require_once('RSStringUtil/RSStringUtil.php');
3 //will print 2.
4 echo '$' . RSStringUtil::bytesToKiloBytes(2000);
5
6 //will print 1.953125.
7 echo '$' . RSStringUtil::bytesToKiloBytes(2000,6);
8 ?>

RSStringUtil::limit

Limits the string passed as first argument to the number of characters passed as second argument and appends the string passed as third argument. Note that the third argument is optional. The default is '...'.


1 <?php
2 require_once('RSStringUtil/RSStringUtil.php');
3 //will print This is my...
4 echo RSStringUtil::limit('This is my text that is too long', 10);
5
6 //will print This is [...]
7 echo RSStringUtil::limit('This is my text that is too long', 8, ' [...]');
8 ?>

RSStringUtil::lastIndexOf

Returns the index of the last occurence of the string passed as second argument in the string passed as first argument. If the search string is not found false is returned.


1 <?php
2 require_once('RSStringUtil/RSStringUtil.php');
3 //will print 17
4 echo RSStringUtil::lastIndexOf('This is my text, my everything.', 'my');
5
6 //will print nothing because the boolean value false is casted to an empty string.
7 echo RSStringUtil::lastIndexOf('This is my text, my everything', 'not there');
8 ?>

Previous Next
RSIO RSValidation

Documentation generated on Mon, 8 Dec 2003 13:10:24 +0100 by phpDocumentor 1.2.3