Wordpress:Stripos功能不适用于卷曲结果

时间:2018-01-31 00:24:09

标签: php wordpress

我正在尝试在curl结果上使用stripos来检查特定的单词。当我在我的functions.php文件中上传这段代码时,我的wordpress网站就崩溃了。

<?php
//create cURL connection
$curl_connection = 
curl_init("https://www.mywebsite2.com/{$info}");

//set options 

curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, 
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);


//perform our request
$result = curl_exec($curl_connection);



//close the connection
curl_close($curl_connection);


$start = strpos($result, 'info1 ');

$end = strpos($result, 'end', $start);

$length = $end-$start;

$result = substr($result, $start, $length);

return $result;

//**************************************************
// Check a word then display 'YES' on my Wordpress website

 if ( (stripos($result,'legend')!== false) {
  echo 'YES';
  }

?>

问题似乎来自stripos功能。

1 个答案:

答案 0 :(得分:0)

您的语法不正确 - 您有一对多(并且您收到cannot use [] for reading错误。

这是正确的语法:

if (stripos($result,'legend')!== false) {
  echo 'YES';
}

请注意从(

中移除if ( (stripos