PHP - 函数名称必须是一个字符串 [英] PHP - Function name must be a string

查看:152
本文介绍了PHP - 函数名称必须是一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:

  PHP注意:未定义变量:exec在第3行的readings.php中
PHP致命错误:函数名必须是第3行的readings.php中的字符串

代码:

 <?php 
require('smarty_config.php');
exec('reading_fetcher.py',$ output,$ ret_code);
$ smarty-> assign('readings',$ output);
$ smarty-> display('readings.tpl');
?>

我被要求输入 reading_fetcher.py 在这里它是:

$ p $ #!/ usr / bin / env python
导入urllib2,re

response = urllib2.urlopen('http://it.ctsfw.edu/inc/nc_scriptureframe.php')

html = response.read()

def remove_html_tags(data):
p = re.compile(r'<。*?>')
return p.sub('',data)

导入重新
导入htmlentitydefs

def convertentity(m):
如果m.group(1)=='#':
try:
返回unichr(int(m.group(2)))
除了ValueError:
return'&#%s;'%m.group(2)
try:
返回htmlentitydefs.entitydefs [m.group(2)]
,除了KeyError:
return'&%s;'%m.group(2)

def converthtml(s ):
return re.sub(r'&(#?)(。+?);',convertentity,s)

readings = converthtml(str(remove_html_t ags(html)))
readings.replace(& nbsp;,)

打印读数[699:]

我已经看过这里此处此处。其中两个错误是额外的$。我的功能名称上没有看到额外的$。第三个错误是使用()而不是[]。所以我试图替换它们。这没有用。我可以尝试什么?

解决方案

exec()可能已被服务器管理员禁用。在这种情况下,对exec的调用将打印E_NOTICE和E_WARNING。因此,如果您禁用了警告打印功能,则只能看到E_NOTICE,并可能会错过更有趣的警告,指出由于安全原因,exec已被禁用。

您可以添加此行到您的代码

  error_reporting(E_ALL); 

以便您可以执行更详细的执行。


The error:

PHP Notice:  Undefined variable: exec in readings.php on line 3
PHP Fatal error:  Function name must be a string in readings.php on line 3

The code:

<?php
    require('smarty_config.php');
    exec('reading_fetcher.py',$output,$ret_code);
    $smarty->assign('readings',$output);
    $smarty->display('readings.tpl');
?>

I was asked for the code of reading_fetcher.py so here it is:

#!/usr/bin/env python
import urllib2, re

response = urllib2.urlopen('http://it.ctsfw.edu/inc/nc_scriptureframe.php')

html = response.read()

def remove_html_tags(data):
    p = re.compile(r'<.*?>')
    return p.sub(' ', data)

import re
import htmlentitydefs

def convertentity(m):
    if m.group(1)=='#':
        try:
            return unichr(int(m.group(2)))
        except ValueError:
            return '&#%s;' % m.group(2)
        try:
            return htmlentitydefs.entitydefs[m.group(2)]
        except KeyError:
            return '&%s;' % m.group(2)

def converthtml(s):
    return re.sub(r'&(#?)(.+?);',convertentity,s)

readings =  converthtml(str(remove_html_tags(html)))
readings.replace("&nbsp;", " ")

print readings[699:]

I already looked here, here and here. Two of those errors are an extra "$". I don't see an extra "$" on my function name. The third error is having "()" instead of "[]". So I tried replacing them. That didn't work. What else might I try?

解决方案

exec() could have been disabled by the server admin. In this scenario a call to exec would print an E_NOTICE and a E_WARNING. So if you disabled warning printing you can only see the E_NOTICE and potentially miss the more interesting warning saying "exec has been disabled for security reason".

You can add this line to your code

error_reporting(E_ALL);

so that you can have a more verbose execution.

这篇关于PHP - 函数名称必须是一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆