How to crop string in typo3 extbase and pi base


 
Following function will crop a string and also append three dots to string.

fixed_lgd_cs($strings,$chars);

$char variable indicates the length.
$stringsvariable indicates the string.

For Example :

$strings = "I am a TYPO3 & PHP Developer";
$chars = 6;

Below function is for PI base. Will work till TYPO3 4.7.XX Version.

$data = t3lib_div::fixed_lgd_cs($strings,$chars); 
echo $data;

Output Will be :

I am a...

It will automatically append three dots at end of the string.

if we use negative number then it will crop that amount of character at end of the string.

Like :

$chars = -9;

Then output Will be :

...Developer

It will automatically append three dots at beginning of the string.

Above script will work for PI base only.

If you want to set this function in ext base fluid then simple you have to use “\TYPO3\CMS\Core\Utility\GeneralUtility” instead of “t3lib_div“.

Following function will work for TYPO3 6.x.xx

$data = \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($strings,$chars);

I hope it will work for you 🙂

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s