Q:

Write a PHP program to create a new string from a given string. If the two characters of the given string from its beginning and end are same return the given string without the first two characters otherwise return the original string

0

Write a PHP program to create a new string from a given string. If the two characters of the given string from its beginning and end are same return the given string without the first two characters otherwise return the original string.

All Answers

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

<?php
function test($s1)
 { 
      if (strlen($s1) > 1 && substr($s1, 0, 2) == substr($s1, strlen($s1) - 2))
          {
              return substr($s1, 2);
           }
      else
          {
              return $s1;
          }
 }

echo test("abcab") . "\n";
echo test("Python") . "\n";

Sample Output:

cab
Python

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