java array to string_数组到字符串转换(Array to string conversion)

数组到字符串转换(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 "%24item_array%5B1%5D%5B'product_img'%5D";

对于其中一个选项: echo "%7B%24item_array%5B1%5D%5B'product_img'%5D%7D";

echo ".%24item_array%5B1%5D%5B'product_img'%5D.";

希望能帮助到你。 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'

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在ThinkPHP6中,当你将一个数组转换字符串时会报错"Array to string conversion"。这个错误通常发生在使用echo或者在字符串拼接过程中出现了数组类型。一种常见的情况是在模板文件中使用了volist标签来循环输出数组中的元素,并且在循环过程中使用了echo或者字符串拼接操作。 为了解决这个问题,你可以尝试以下方法: 1. 确保你的代码中没有直接将数组作为字符串输出或者拼接。在使用echo输出变量时,确保变量是字符串类型而不是数组类型。你可以使用var_dump或print_r函数来检查变量的类型和内容。 2. 如果你在模板文件中使用volist标签来循环输出数组中的元素,确保在循环过程中正确地使用了数组的键值。在volist标签中,通过$v['name']来获取数组中的元素是正确的方式。确保你没有将$v作为字符串输出或者拼接。 3. 如果你的代码中存在字符串拼接操作,并且拼接的过程中包含了数组类型,你可以使用implode函数将数组转换字符串后再进行拼接。例如,如果你有一个数组$arr,你可以使用implode(',', $arr)将数组转换为以逗号分隔的字符串。 总结一下,当在ThinkPHP6中出现"Array to string conversion"错误时,需要检查代码中是否直接将数组作为字符串输出或者拼接,以及在使用volist标签循环输出数组时是否正确使用了数组的键值。如果存在字符串拼接操作,可以使用implode函数将数组转换字符串后再进行拼接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值