Write a PHP program to create a new string taking the first 3 characters of a given string and return the string with the 3 characters added at both the front and back. If the given string length is less than 3, use whatever characters are there
- برمجة بي اتش بي
- 2021-09-08
- mhanasmh00489829403
الأجوبة
<?php
function test($str)
{
if (strlen($str) < 3)
{
return $str.$str.$str;
}
else
{
$front = substr($str, 0, 3);
return $front.$str.$front;
}
}
echo test("Python")."\n";
echo test("JS")."\n";
echo test("Code")."\n";
Sample Output:
PytPythonPyt JSJSJS CodCodeCod
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال