Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$s = 'JavaScript';
$t = str_replace('Java', 'Type', $s);
echo substr($s, 4), ' ', substr($s, -6, 3), ' ', $s, ' ', $t, "\n";Script Scr JavaScript TypeScript
- Expecting
str_replaceto change$s: it returns a new string, which lands in$t, while$skeepsJavaScript. - Counting
substrpositions from 1: the first character is at position 0, sosubstr($s, 4)starts atSand givesScript.
- How would you make
$sitself holdTypeScript? - What does
substr($s, -3)return here, and why?