数组到字符串转换

时间:2015-06-07 10:59:27

标签: php

我有错误

第26行的数组到字符串转换

为什么会这样,我该如何解决?谢谢

$strona = file_get_contents('http://sd');
$preg = preg_match('/base\=\"([^\"]*)\"/iU', $strona, $rt);


$strona = file_get_contents('http://sd');
$preg = preg_match('/src\=\"([^\"]*)\"/iU', $strona, $tok);




$link = $rt."/".$tok;

echo $link[1];

2 个答案:

答案 0 :(得分:0)

preg_match返回匹配为数组。 $ matches [0]将包含与完整模式匹配的文本,$ matches [1]将具有与第一个捕获的带括号的子模式匹配的文本。

   $strona = file_get_contents('http://sd'); 
   $preg_rt = preg_match('/base\=\"([^\"]*)\"/iU', $strona, $rt);
   $preg_tok = preg_match('/src\=\"([^\"]*)\"/iU', $strona, $tok);
   if ($preg_rt && $preg_tok) 
       $link = $rt[1]."/".$tok[1]; // all OK
   else  {  // not found 
   }

答案 1 :(得分:0)

好吧,我想通了,它应该是这样的:

$strona = file_get_contents('http://sd'); $preg = preg_match('/base\=\"([^\"]*)\"/iU', $strona, $rt);

$strona = file_get_contents('http://sd'); $preg = preg_match('/src\=\"([^\"]*)\"/iU', $strona, $tok);

$link = $rt[1]."/".$tok[1];

echo $link;
相关问题