Files
luowei/program_85.php
2025-01-08 18:48:04 +08:00

30 lines
665 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// 自定义函数实现首尾字母交换
function mySwap($string) {
// 检查字符串是否为空或长度为1
if (strlen($string) <= 1) {
return $string;
}
// 获取首字母和尾字母
$firstChar = $string[0];
$lastChar = $string[strlen($string) - 1];
// 替换首尾字母
$swappedString = $lastChar . substr($string, 1, -1) . $firstChar;
return $swappedString;
}
// 获取URL传递的字符串
if (isset($_GET['string'])) {
$string = $_GET['string'];
// 输出结果
echo mySwap($string);
} else {
echo "请通过URL传递字符串例如program_85.php?string=example";
}
?>
<?php