Q:

Write a PHP program to create a new string without the first and last character of a given string of any length

0

Write a PHP program to create a new string without the first and last character of a given string of any length

All Answers

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

<?php
function test($s1)
{ 

  return strlen($s1) < 2 ? "" : substr($s1, 1, strlen($s1) - 2);

}

echo test("Hello")."\n";
echo test("JS")."\n";
echo test("  ")."\n";

Sample Output:

ell

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