Write a PHP program to check if a given string begins with 'abc' or 'xyz'. If the string begins with 'abc' or 'xyz' return 'abc' or 'xyz' otherwise
- برمجة بي اتش بي
- 2021-09-08
- mhanasmh00489829403
الأجوبة
<?php
function test($s1)
{
if (substr($s1,0,3) == "abc")
{
return "abc";
}
else if (substr($s1,0,3) == "xyz")
{
return "xyz";
}
else
{
return "";
}
}
echo test("abc")."\n";
echo test("abcdef")."\n";
echo test("C")."\n";
echo test("xyz")."\n";
echo test("xyzsder")."\n";
Sample Output:
abc abc xyz xyz
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال