PHP - Function name must be a string
The er开发者_如何学Pythonror:
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(" ", " ")
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.
精彩评论