Q:

Write a PHP program to check if a given string ends with "on"

0

Write a PHP program to check if a given string ends with "on".

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function test($s1, $n)
{ 
 
   return substr($s1, 0, $n) . substr($s1, strlen($s1) - $n, $n);

}

echo test("Hello", 1)."\n";
echo test("Python", 2)."\n";
echo test("on", 1)."\n";
echo test("o", 1)."\n";

Sample Output:

Ho
Pyon
on
oo

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now