Table of Contents
<h2>Slicing Strings</h2>
<p>From w3schools.com, Experiment by Teeratus_R </p>
<h4>Slicing</h4>
<p>Start the slice at index 6 and end the slice 5 positions later:</p>
<?php
$x = "Hello World!";
echo substr($x, 6, 5);
?>
<h4>Slice to the End</h4>
<p>Start the slice at index 6 and go all the way to the end:</p>
<?php
$x = "Hello World!";
echo substr($x, 6);
?>
<h4>Slice From the End</h4>
<p>Get the 3 characters, starting from the "o" in world (index -5):</p>
<?php
$x = "Hello World!";
echo substr($x, -5, 3);
?>
<h4>Negative Length</h4>
<?php
$x = "Hi, how are you?";
echo substr($x, 5, -3);
?>
Result View Example
Document in project
You can Download PDF file.