Q:

Write a PHP program to check if a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string

0

Write a PHP program to check if a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' 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($s) 
{
   return substr($s, 1, 2) == "yt" ? substr($s, 0, 1).substr($s, 3, strlen($s)-2) : $s;
}

echo test("Python")."\n";
echo test("ytade")."\n";
echo test("jsues")."\n";

Sample Output:

Phon
ytade
jsues

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