且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP函数未定义的变量问题

更新时间:2022-04-25 10:04:38

这是因为您使用 $ pera 变量(它只存在于全局s中) )

This is because you're using the $pera variable (which exists only in the global scope) inside a function.

请参阅

See the PHP manual page on variable scope for more information.

你可以通过添加 global $ pera来解决这个问题。 ; 在你的函数中,尽管这不是一个特别优雅的方法,因为全局变量因为太详细的原因而被忽略掉了。因此,***接受 $ pera 作为你函数的参数,如下所示:

You could fix this by adding global $pera; within your function, although this isn't a particularly elegant approach, as global variables are shunned for reasons too detailed to go into here. As such, it would be better to accept $pera as an argument to your function as follows:

function provera($prom, $pera){
    if (preg_match("/[0-9\,\.\?\>\.<\"\'\:\;\[\]\}\{\/\!\\\@\#\$\%\^\&\*\(\)\-\_\=\+\`[:space:]]/",$prom)){
        echo "Nepravilan unos imena ili prezimina!";
        echo $pera;
        }
}