2013-04-23 39 views
0

我最近更改我的服務器代碼不再工作,而在我的舊服務器上它完美地工作。未定義的抵消:1 file_get_contents

<?php 
ini_set('display_errors', 1); 
ini_set('error_reporting', E_ALL | E_STRICT); 

$myid = "110988448104041785223"; 
$plus = file_get_contents("http://plus.google.com/$myid/plusones"); 
$match = array(); 
preg_match('/<div aria-hidden="true" class="BT"><a href="(.*?)"/',$plus,$match); 
$data['url'] = $match[1]; 
echo strtolower($data['url']); 
?> 

Reurn:未定義抵消:1 ....第9行

我在.htaccess中添加了這個(我不知道這是否是必要的):

php_value magic_quotes 0 
php_flag magic_quotes Off 
php_value magic_quotes_gpc 0 
php_flag magic_quotes_gpc Off 
php_flag allow_url_include On 

PHP版本5.2.17 - 舊服務器WORK FINE;和PHP版本5.3.23 - 新服務器。

感謝

+0

'$匹配[1]'不存在我猜。在嘗試使用它們之前請檢查您的配對 – 2013-04-23 18:36:03

+0

您可以檢查這個嗎? http://codepad.viper-7.com/bNeBUV – Felix 2013-04-23 19:13:58

回答

0

這意味着它沒有找到匹配,但您正在嘗試無論訪問結果數組。

你應該有這樣的:

if(preg_match('/<div aria-hidden="true" class="BT"><a href="(.*?)"/',$plus,$match)) { 
    $data['url'] = $match[1]; 
    echo strtolower($data['url']); 
} 
else echo "ERROR: No match found!"; 
+0

謝謝,但通常他必須找到一個匹配... [鏈接](http://codepad.viper-7.com/bNeBUV) – Felix 2013-04-23 19:11:16