Q:

Write a PHP program to convert the last 3 characters of a given string in upper case. If the length of the string has less than 3 then uppercase all the characters

0

Write a PHP program to convert the last 3 characters of a given string in upper case. If the length of the string has less than 3 then uppercase all the characters

All Answers

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

<?php
function test($s) 
{
   return strlen($s) < 3 ? strtoupper($s) : substr($s, 0, strlen($s) - 3).strtoupper(substr($s, strlen($s) - 3));
 }


echo test("Python")."\n";
echo test("Javascript")."\n";
echo test("js")."\n";
echo test("PHP")."\n";

Sample Output:

PytHON
JavascrIPT
JS
PHP

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