数组到字符串转换(Array to string conversion)
这段代码有什么问题? 我不明白。 这是错误代码:
注意:第12行的C:\ xampp \ htdocs \ stage \ ripper.php中的数组到字符串转换数组块引用
注意:第13行数组中C:\ xampp \ htdocs \ stage \ ripper.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\"\>(.*)\(.*)\
Taal:(.*)\(.*)\>(.*)\\(.*)\data-src-l\/sU";
preg_match_all($pattern, $htmlcode, $matches);
Print_r ($matches);
$description =($matches[1]);
$language = ($matches[3]);
echo $description;
echo $language
?>
What's the problem of this code? I don't get it. This is the error code:
Notice: Array to string conversion in C:\xampp\htdocs\stage\ripper.php on line 12 Array Blockquote
Notice: Array to string conversion in C:\xampp\htdocs\stage\ripper.php on line 13 Array
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\"\>(.*)\(.*)\
Taal:(.*)\(.*)\>(.*)\\(.*)\data-src-l\/sU";
preg_match_all($pattern, $htmlcode, $matches);
Print_r ($matches);
$description =($matches[1]);
$language = ($matches[3]);
echo $description;
echo $language
?>
原文:https://stackoverflow.com/questions/26377015
更新时间:2020-02-29 18:37
最满意答案
当您使用preg_match_all , $matches是一个二维数组。 所以$matches[1]和$matches[3]都是数组。 echo仅适用于数字或字符串,因此当您尝试回显数组时会收到警告。 如果要查看其中的内容,请使用print_r()或var_dump() :
print_r($description);
print_r($language);
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);
2014-10-15
相关问答
对我来说似乎完全合法; char *[3]衰变为char ** ,所以赋值应该是有效的。 GCC 4.4.5和CLang 1.1都没有抱怨。 Seems perfectly legal to me; char *[3] decays to char **, so the assignment should be valid. Neither GCC 4.4.5 nor CLang 1.1 complains.
要开始你的作业, String.split将正则表达式分割字符串,此表达式可能是一个空字符串: String[] ary = "abc".split("");
产生数组: (java.lang.String[]) [, a, b, c]
摆脱空的第一个条目留给读者练习:-) 注意:在Java 8中,不再包含空的第一个元素。 To start you off on your assignment, String.split splits strings on a regular expressi
...
serialize数据:
然后反unserialize : <?php
$youralldata = unserialize($_POST['data']);
print_r($youralldata);
?>
serialize the data:
...
the_given_string.scan(/"(.*?)"/).flatten
the_given_string.scan(/"(.*?)"/).flatten
$list = array ($_POST["array"]);
如果$_POST['array']已经是一个数组, Array($_POST['array'])将产生[一个]数组字符串数组。 如果你写print_r($list) ,你会看到类似这样的东西: Array(0 =>
Array(
0 => "0",
1 => "0",
2 => "0",
3 => "0",
4 => "0",
5 => "0",
6 => "0",
7 => "0
...
你在char[]上调用toString并继承Object的实现,所以你得到了char[].class名字,然后是对象的哈希。 相反,调用String(char[])构造函数: nid_txt.setText(new String(emp.nid));
You're calling toString on a char[] - and that inherits the implementation from Object, so you get the char[].class name, @
...
你只需要使用正确的字符串连接。 改变这一行: echo "
";
对于其中一个选项: echo "
";
echo "
";
希望能帮助到你。 You just need to use proper string concatenation. Change
...
您收到错误,因为$pages是一个数组。 看起来你想要吐出该数组中的项目数,在这种情况下你应该用count($pages)替换$pages 。 echo '
', $prevlink, ' Page ', $page, ' of ',
count($pages), ' pages, displaying ', $start, '-', $end, ' of ', count($total),
'results ', $nextlink,
...
当您使用preg_match_all , $matches是一个二维数组。 所以$matches[1]和$matches[3]都是数组。 echo仅适用于数字或字符串,因此当您尝试回显数组时会收到警告。 如果要查看其中的内容,请使用print_r()或var_dump() : print_r($description);
print_r($language);
When you use preg_match_all, $matches is a 2-dimensional array. So $
...
你这样做: echo'
(line 248) '.$ids = array();
基本上,您不能将数组与字符串连接,这就是出现错误的原因。 要修复错误,可以将数组声明分隔为单独的行: echo'
';
$ids = array();
希望这可以帮助! You're doing this: echo'
(line 248) '.$ids = array();
Basically, you can'
...