String Cutting in PHP
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 there are more than 5 characters, output the first 5 with an ellipsis, otherwise output the entire string:
'This ...'
Given a string:
<?php
$str = 'многобайтовые строки требуют особого подхода';
?>
Cut the last word:
'подхода'
Given a string:
<?php
$str = 'пример работы с кириллическими символами';
?>
Cut and output:
'работы'
'кириллическими'