函数未定义


ReferenceError, Function not Defined

我是php的新手,我试着写这个函数。现在看起来函数没有定义。当我打开php文件并尝试使用console运行它时,什么也没有发生。它给出了一个错误——

contentcheck("ex1.php"、"Bajestani")

ReferenceError: contentcheck is not defined

代码如下。

<?php
if(contentcheck('ex1.php','Bajestani')===true)
    echo 'Got it';
function contentcheck($filename,$phrase)
{
    $content = shell_exec('C:'xampp'htdocs'docman'pdftotext '.$filename.' -');
    if (strpos($content,$phrase) !== false) 
    {
        return true;
    }
    else 
        return false;
}
if(contentcheck('ex1.php','Bajestani')===true)
    echo 'Got it';
?>

Thanks In advance

您声明您尝试从控制台中运行该函数。

另外,ReferenceError: contentcheck is not defined是一个Javascript错误,而不是PHP错误。

这两个事实使我得出结论,你试图从浏览器内部运行PHP代码。

请注意,PHP代码在浏览器中不可用——如果在控制台中运行,函数确实是未定义的,因为PHP是在web服务器上运行的,而不是在浏览器中。浏览器永远不会看到你的PHP函数;它只是看到PHP程序的输出(例如HTML代码等,由PHP程序打印)。PHP代码本身永远不会被浏览器看到。

你并不完全清楚你的程序应该做什么,但很清楚的是,你试图运行它的方式是行不通的。您将不得不彻底重新考虑这一点,并可能更多地了解客户机/服务器系统如何工作,特别是PHP。