-
Notifications
You must be signed in to change notification settings - Fork 1
StringBuilder
The string builder is used to easily concatenate strings in an object oriented way. It is optimized for outputting HTML, with common snippets, and ties into the Application Localization package for translating texts.
The basic principle is that every bit of text is automatically prepended with a space (except the first), to avoid having to add them manually. Each method returns the same StringBuilder
instance, allowing them to be chained.
echo sb()
->add('First sentence.')
->add('Second sentence.')
->add('And a last one.');
echo sb()
->sf('Text with a %1$s.', 'placeholder');
echo sb()->bold('This is bold text.');
echo sb()->eol();
echo sb()->nl();
Default is to add two <br>
tags:
echo sb()->para();
To add a <p>
tag instead, specify some content:
echo sb()->para('Some text here');
echo sb()->link('AppUtils', 'https://github.com/Mistralys/application-utils');
Opening the link in a new tab/window:
echo sb()->link('AppUtils', 'https://github.com/Mistralys/application-utils', true);
echo sb()->t('This text will be translated.');
New here?
Have a look at the overview for a list of all helper classes available in the package.
Table of contents
Find the current page in the collapsible "Pages" list above, and expand the page, to view a table of contents.