-2

i have an error

Array to string conversion on line 26

why is it happening and how can i solve it? thank you

$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];
kamal pal
  • 4,187
  • 5
  • 25
  • 40
user3412188
  • 31
  • 1
  • 8
  • How many matches do you wait? only one? or maybe several results? – splash58 Jun 07 '15 at 11:05
  • those 2 commands are getting rtmp address and it token line, then i'm trying to make them together as a one link in the next command. there is only one result. When i input echo $rt[1], or echo $tok[1] seperately, it shows both results without any error, but when i put it into line like: $link = $rt[1]."/".$tok[1], it shows only one letter instead of the full link i don't know why – user3412188 Jun 07 '15 at 11:12

2 Answers2

0

preg_match return Matches as array. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern.

   $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 
   }
splash58
  • 26,043
  • 3
  • 22
  • 34
0

okay, i figured it out, it should be something like:

$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;
splash58
  • 26,043
  • 3
  • 22
  • 34
user3412188
  • 31
  • 1
  • 8