严格标准:第27行的get_id.php中只能通过引用传递变量
我在php中收到以下通知:严格标准:第27行的get_id.php中只能通过引用传递变量,php,variables,reference,standards,strict,Php,Variables,Reference,Standards,Strict,我在php中收到以下通知: 严格标准:第27行的get_id.php中只能通过引用传递变量 代码是: <?php function truncate($text, $length, $suffix ='', $isHTML = true) { $i = 0; $simpleTags=array('br'=>true,'hr'=>true,'input'=>true,'image'=>true,'link'=>true,'meta'=>tr
严格标准:第27行的get_id.php中只能通过引用传递变量 代码是:
<?php
function truncate($text, $length, $suffix ='', $isHTML = true) {
$i = 0;
$simpleTags=array('br'=>true,'hr'=>true,'input'=>true,'image'=>true,'link'=>true,'meta'=>true);
$tags = array();
if($isHTML){
preg_match_all('/<[^>]+>([^<]*)/', $text, $m, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
foreach($m as $o){
if($o[0][1] - $i >= $length)
break;
$t = substr(strtok($o[0][0], " \t\n\r\0\x0B>"), 1);
// test if the tag is unpaired, then we mustn't save them
if($t[0] != '/' && (!isset($simpleTags[$t])))
$tags[] = $t;
elseif(end($tags) == substr($t, 1))
array_pop($tags);
$i += $o[1][1] - $o[0][1];
}
}
// output without closing tags
$output = substr($text, 0, $length = min(strlen($text), $length + $i));
// closing tags
$output2 = (count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : '');
// Find last space or HTML tag (solving problem with last space in HTML tag eg. <span class="new">)
$pos = (int)end(end(preg_split('/<.*>| /', $output, -1, PREG_SPLIT_OFFSET_CAPTURE)));
// Append closing tags to output
$output.=$output2;
// Get everything until last space
$one = substr($output, 0, $pos);
// Get the rest
$two = substr($output, $pos, (strlen($output) - $pos));
// Extract all tags from the last bit
preg_match_all('/<(.*?)>/s', $two, $tags);
// Add suffix if needed
if (strlen($text) > $length) { $one .= $suffix; }
// Re-attach tags
$output = $one . implode($tags[0]);
//added to remove unnecessary closure
$output = str_replace('</!-->','',$output);
return $output;
}
?>
这里有很多类似的问题
end希望其参数是通过引用传递的,并且只有变量可以通过引用传递(而不是另一个函数的返回值,如您的例子中的preg_split)
最简单的解决方案应该是将调用拆分为单独的行,例如
$splitted = preg_split('/<.*>| /', $output, -1, PREG_SPLIT_OFFSET_CAPTURE);
$last_item = end($splitted);
$very_last_item = end($last_item);
$splitted=preg_split('/|/',$output,-1,preg_split_OFFSET_CAPTURE);
$last_item=结束($splitted);
$very_last_item=结束($last_item);
或者,如果您有时间和资源,可以重新编写此函数,这样就不必结束()调用
(很抱歉,我有点不明白您想在这里完成什么)它的end()需要一个引用,因为它更改了内部数组值指针。一般提示:如果您发布了一堆代码,只在is处抛出一个行号,请指示该行的位置。不要强迫我们手动计算行数。同样,不要使用正则表达式来解析html。你最终会遇到这样可怕的怪物。改用DOM。“只有变量应该在第27行的get_id.php中通过引用传递”——我想这与wampserver无关。我想这将是php版本的问题。可能重复的感谢它的工作非常感谢。。这是我的第一个问题。你们都很快解决了这个问题非常感谢。。。