无法使用自定义函数在PHP中格式化字符串
您需要将所有操作的结果指定给即将返回的变量无法使用自定义函数在PHP中格式化字符串,php,string,function,Php,String,Function,您需要将所有操作的结果指定给即将返回的变量 <?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;
<?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;
?>
1用htmlentities替换htlmentities 正如前面的评论所说
<?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;
?>
您的代码有两个问题
function varform($var){
return ucwords(strtolower(htmlentities(trim($var))));
}
您需要从PHP方法中获取返回值,并从函数中返回该值
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
}
欢迎使用SO,请使用提供的格式化工具格式化您的问题。这次我帮你把它清理干净了。htlmentities就是htmlentities你打错了mistake@johnP-谢谢,我现在也把它修好了
function varform($var){
$var = ucwords(strtolower(htmlentities(trim($var))));
return $var;
}