Q:

Write a PHP program to create a new string taking 3 characters from the middle of a given string at least 3

0

Write a PHP program to create a new string taking 3 characters from the middle of a given string at least 3.

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) - 1) / 2 - 1, 3);

}

echo test("Hello")."\n";
echo test("Python")."\n";
echo test("abc")."\n";

Sample Output:

ell
yth
abc

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