数组到字符串的转换 [英] Array to string conversion
问题描述
此代码有什么问题?我不明白这是错误代码:
What's the problem of this code? I don't get it. This is the error code:
注意:数组到字符串的转换第12行数组上的C:\ xampp \ htdocs \ stage \ ripper.php引用
Notice: Array to string conversion in C:\xampp\htdocs\stage\ripper.php on line 12 Array Blockquote
注意:C:\ xampp \ htdocs \ stage \ ripper.php中的数组到字符串的转换在第13行数组上
Notice: Array to string conversion in C:\xampp\htdocs\stage\ripper.php on line 13 Array
<?php
header('Content-Type: text/html; charset=utf-8');
$url = "http://www.asaphshop.nl/epages/asaphnl.sf/nl_NL/ObjectPath=/Shops/asaphnl/Products/80203122";
$htmlcode = file_get_contents($url);
$pattern = "/itemprop=\"description\"\>(.*)\<\/div\>(.*)\<li\>Taal:(.*)\<\/li\>(.*)\>(.*)\<\/div\>\<li\>(.*)\data-src-l\<\/li\>/sU";
preg_match_all($pattern, $htmlcode, $matches);
Print_r ($matches);
$description =($matches[1]);
$language = ($matches[3]);
echo $description;
echo $language
?>
推荐答案
使用 preg_match_all
时, $ matches
是二维数组.因此, $ matches [1]
和 $ matches [3]
都是数组. echo
仅适用于数字或字符串,因此当您尝试回显数组时会收到警告.如果要查看其中的内容,请使用 print_r()
或 var_dump()
:
When you use preg_match_all
, $matches
is a 2-dimensional array. So $matches[1]
and $matches[3]
are both arrays. echo
only works with numbers or strings, so you get a warning when you try to echo an array. If you want to see what's in them, use print_r()
or var_dump()
:
print_r($description);
print_r($language);
这篇关于数组到字符串的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!