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)
{ 
 
   return substr($s1, strlen($s1)-2, 2);

}

var_dump(test("Hello"));
var_dump(test("Python"));
var_dump(test("on"));
var_dump(test("o"));

Sample Output:

string(2) "lo"
string(2) "on"
string(2) "on"
string(1) "o"

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