⊗ppPmSFCt 150 of 447 menu

String Cutting in PHP

substr mb_substr mb_strcut

Given a string:

<?php $str = 'html css php'; ?>

Cut from our string and output:

'html' 'css' 'php'

Given a string:

<?php $str = 'abcdefgh'; ?>

Output the last 3 characters:

'fgh'

Given a string:

<?php $str = 'http://example.com'; ?>

Check that it starts with 'http://':

Given a string:

<?php $str = 'https://example.com'; ?>

Check that it starts with 'http://' or 'https://':

Given a string:

<?php $str = 'image.png'; ?>

Check that it ends with '.png':

Given a string:

<?php $str = 'photo.jpg'; ?>

Check that it ends with '.png' or '.jpg':

Given a string:

<?php $str = 'This is a long string'; ?>

If characters > 5, output first 5 with an ellipsis, otherwise the whole string:

'This ...'

Given a string:

<?php $str = 'многобайтовые строки требуют особого подхода'; ?>

Cut the last word:

'подхода'

Given a string:

<?php $str = 'пример работы с кириллическими символами'; ?>

Cut and output:

'работы' 'кириллическими'
byenru