【发布时间】:2014-09-07 02:07:44
【问题描述】:
当我尝试运行脚本时
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;
}
}
?>
【问题讨论】:
-
不能给函数返回调用赋值,如果你想让
$ini与strpos的返回值相等,请将$ini放在strpos之前
标签: php runtime-error