Is there a one line way to combine getting first and last character of a string?
I tried (without success):
$title = "IncredibleTitle";
$title_characters = (mb_substr($title, 0, 1, 'UTF8')) && (mb_substr($title, 0, -1, 'UTF8'));
>Solution :
- Use
.period character for concatenation. - To get last character, 2nd param has to be -1 and third param will be value 1 or the length. See
mb_substr.
Snippet:
<?php
$title = "IncredibleTitle";
$title_characters = (mb_substr($title, 0, 1, 'UTF8')) . (mb_substr($title, -1, 1, 'UTF8'));
echo $title_characters;