<?php
$string = 'tHis is aN unEVen string that needs to be formated properly';
// custom function created combining multiple functions
function varform($var){
ucwords(strtolower(htlmentities(trim($var))));
return $var;
}
$string = varform($string);
echo $string;
?>
答案 0 :(得分:3)
您需要将所有操作的结果分配给即将返回的变量
<?php
$string = 'tHis is aN unEVen string that needs to be formated properly';
// custom function created combining multiple functions
function varform($var){
// assign change to the variable
$var = ucwords(strtolower(htmlentities(trim($var))));
return $var;
}
$string = varform($string);
echo $string;
?>
答案 1 :(得分:3)
您的代码存在两个问题
function varform($var){
ucwords(strtolower(htlmentities(trim($var))));
------------------------^ //It's htmlentities() not htlmentities()
return $var; //you're just returning the value that is passed to the method
}
您需要从PHP方法获取返回值并从函数中返回
function varform($var){
$var = ucwords(strtolower(htmlentities(trim($var))));
return $var;
}
答案 2 :(得分:2)
1)用htmlentities替换htlmentities
正如之前的评论者所说
function varform($var){
return ucwords(strtolower(htmlentities(trim($var))));
}