substr, from position $n to end:
You can extract a small segment from a string from a position $n to the end:
<?php
$part = substr("I'm in Europe now", 7 ); // $part = "Europe now"
?>
$part = substr("I'm in Europe now", 7 ); // $part = "Europe now"
?>
substr, from position $n1 to $n2 :
You can choose, in substr() parameters, how many characters to extract after the position $n:
<?php
$part = substr("I'm in Europe now", 7 , 6 ); // $part = "Europe"
$part = substr("I'm in Europe now", 7 , 3 ); // $part = "Eur"
?>
$part = substr("I'm in Europe now", 7 , 6 ); // $part = "Europe"
$part = substr("I'm in Europe now", 7 , 3 ); // $part = "Eur"
?>
You can output the $n last character from a string:
<?php
$part = substr("I'm in Europe now", -3 ); // $part = "now"
?>
$part = substr("I'm in Europe now", -3 ); // $part = "now"
?>
You may choose the start position with a negatif number, from the end of the string ( like we see in the previous code):
<?php
$part = substr("I'm in Europe now", -3 ); // $part = "now"
$part = substr("I'm in Europe now", -3 , 2 ); // $part = "no"
?>
$part = substr("I'm in Europe now", -3 ); // $part = "now"
$part = substr("I'm in Europe now", -3 , 2 ); // $part = "no"
?>
<?php
$part = substr("I'm in Europe now", 7 , -4 ); // $part = "Europe"
?>
$part = substr("I'm in Europe now", 7 , -4 ); // $part = "Europe"
?>