Initial commit
This commit is contained in:
29
20241208/program_85.php
Normal file
29
20241208/program_85.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?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
|
Reference in New Issue
Block a user