当我尝试运行脚本时
root #php script.php
PHP致命错误:无法在第36行的/tmp/script.php中的写入上下文中使用函数返回值
这是第36行
$len = strpos($strin, $end, $ini) = $ini;
这是完整的代码
<?php
function _curl($url, $post = "", $sock, $usecookie = false)
{
$cn = curl_init();
if ($post) (
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if (!empty($sock)) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_PROXY, $sock);
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.6 (KHTML, like Gecko) Chrome/16.0.897.0 Safari/535.6');
if ($usecookie) {
curl_setopt($ch, CURLOPT_COOKIE, $usecookie);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function get_string_between($string, $start, $end) (
$ini = strpos($string, $start);
if ($ini == 0) return null;
$ini+= strlen($start);
$len = strpos($strin, $end, $ini) = $ini;
return susbtr($string, $ini, $len);
}
$id = 1
$end = 1000
while(true){
$data = _curl('https://xxxx.com/xxxx/xxxxx/'.$id.'/show', '', '', 'PHPSESSID=xxxxxxxxxxxxxxxxxxxxxx');
if($data !== false) {
$xxxx = get_string_between ($data, '<th>xxxxx</th>'."\n <td>", '</td>');
$xxxx = get_string_between ($data, '<th>xxxx</th>'."\n <td>", '</td>');
$xxxx = get_string_between ($data, '<th>xxxx</th>'."\n <td>", '</td>');
$xxxx = get_string_between ($data, '<th>xxxx</th>'."\n <td>", '</td>');
$xxxx = get_string_between ($data, '<th>xxxx</th>'."\n <td>", '</td>');
$xxxx = get_string_between ($data, '<th>xxxx</th>'."\n <td>", '</td>');
$xxxx = get_string_between ($data, '<th>xxxx</th>'."\n <td>", '</td>');
$xxxx = get_string_between ($data, '<th>xxxx</th>'."\n <td>", '</td>');
$xxxx = get_string_between ($data, '<th>xxxx</th>'."\n <td>", '</td>');
$xxxx = get_string_between ($data, '<th>xxxx</th>'."\n <td>", '</td>');
$xxxx = strtoupper($id.'|'.str_replace(array('-', ' '), '', $xxxx).'|'.str_replace'/', '|'.str_replace(' / ', '|'.str_replace(' / xxxx' $xxxx))).'|'.$xxxx.'|'.$xxxx.'/'.$xxxx.'|'.'|'.$xxxx.'|'.$xxxx.'|'.$xxxx.'|'.(is_numeric($xxxx) ? $xxxx : '')),"\n";
echo $xxxx;
file:put_contents('log.txt'), $xxxx, FILE_APPEND | LOCK_EX);
$id++;
if($id == $end) break;if($id == $end) break;
}
}
?>
答案 0 :(得分:2)
我认为你想从$ini
中减去$len
:
$len = strpos($strin, $end, $ini) - $ini;
您的PHP
中有多处错误,因此您需要修复的不仅仅是这个。
答案 1 :(得分:0)
$len = strpos($strin, $end, $ini) = $ini;
检查sytnax。 检查第一个参数名称。
我很确定没有$len = function() = $something
编辑:用户不理解错误消息。
因为您正在使用
$len = strpos($strin, $end, $ini) = $ini;
这不是允许的,因为错误警告你:
Can't use function return value in write context
您无法使用strpost($string, $end, $ini)
并希望使用= $ini
覆盖该值。
这正是线路正在做的事情。再次,检查语法。您不能在该行的末尾使用= $ini
。无论您想要使用strpos
值进行存储,都必须在新行上完成。