【问题标题】:Can't use function return value in write context in不能在写入上下文中使用函数返回值
【发布时间】: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;
}

}

?>      

【问题讨论】:

  • 不能给函数返回调用赋值,如果你想让$inistrpos的返回值相等,请将$ini放在strpos之前

标签: php runtime-error


【解决方案1】:

我想你想从$len 中减去$ini

$len = strpos($strin, $end, $ini) - $ini;

您的PHP 中有多个错误,因此您需要修复的不仅仅是这个。

【讨论】:

    【解决方案2】:
    $len = strpos($strin, $end, $ini) = $ini;
    

    检查语法。 检查第一个参数名称。

    我很确定没有$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 值做什么存储,都必须在新行上完成。

    【讨论】:

    • $len = strpos($strin, $end, $ini) = $ini; --> $len = strpos($string, $end, $ini) = $ini;我遇到了同样的错误
    猜你喜欢
    • 2014-09-08
    • 1970-01-01
    • 1970-01-01
    • 2015-04-13
    • 1970-01-01
    • 2012-09-08
    • 2016-09-02
    • 1970-01-01
    相关资源
    最近更新 更多