java array to string_数组到字符串转换(Array to string conversion)
數(shù)組到字符串轉(zhuǎn)換(Array to string conversion)
這段代碼有什么問題? 我不明白。 這是錯(cuò)誤代碼:
注意:第12行的C:\ xampp \ htdocs \ stage \ ripper.php中的數(shù)組到字符串轉(zhuǎn)換數(shù)組塊引用
注意:第13行數(shù)組中C:\ xampp \ htdocs \ stage \ ripper.php中的數(shù)組到字符串轉(zhuǎn)換
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
更新時(shí)間:2020-02-29 18:37
最滿意答案
當(dāng)您使用preg_match_all , $matches是一個(gè)二維數(shù)組。 所以$matches[1]和$matches[3]都是數(shù)組。 echo僅適用于數(shù)字或字符串,因此當(dāng)您嘗試回顯數(shù)組時(shí)會收到警告。 如果要查看其中的內(nèi)容,請使用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
相關(guān)問答
對我來說似乎完全合法; char *[3]衰變?yōu)閏har ** ,所以賦值應(yīng)該是有效的。 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.
要開始你的作業(yè), String.split將正則表達(dá)式分割字符串,此表達(dá)式可能是一個(gè)空字符串: String[] ary = "abc".split("");
產(chǎn)生數(shù)組: (java.lang.String[]) [, a, b, c]
擺脫空的第一個(gè)條目留給讀者練習(xí):-) 注意:在Java 8中,不再包含空的第一個(gè)元素。 To start you off on your assignment, String.split splits strings on a regular expressi
...
serialize數(shù)據(jù):
然后反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']已經(jīng)是一個(gè)數(shù)組, Array($_POST['array'])將產(chǎn)生[一個(gè)]數(shù)組字符串?dāng)?shù)組。 如果你寫print_r($list) ,你會看到類似這樣的東西: Array(0 =>
Array(
0 => "0",
1 => "0",
2 => "0",
3 => "0",
4 => "0",
5 => "0",
6 => "0",
7 => "0
...
你在char[]上調(diào)用toString并繼承Object的實(shí)現(xiàn),所以你得到了char[].class名字,然后是對象的哈希。 相反,調(diào)用String(char[])構(gòu)造函數(shù): 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 "";
對于其中一個(gè)選項(xiàng): echo "";
echo "";
希望能幫助到你。 You just need to use proper string concatenation. Change
...
您收到錯(cuò)誤,因?yàn)?pages是一個(gè)數(shù)組。 看起來你想要吐出該數(shù)組中的項(xiàng)目數(shù),在這種情況下你應(yīng)該用count($pages)替換$pages 。 echo '
', $prevlink, ' Page ', $page, ' of ',
count($pages), ' pages, displaying ', $start, '-', $end, ' of ', count($total),
'results ', $nextlink,
...
當(dāng)您使用preg_match_all , $matches是一個(gè)二維數(shù)組。 所以$matches[1]和$matches[3]都是數(shù)組。 echo僅適用于數(shù)字或字符串,因此當(dāng)您嘗試回顯數(shù)組時(shí)會收到警告。 如果要查看其中的內(nèi)容,請使用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();
基本上,您不能將數(shù)組與字符串連接,這就是出現(xiàn)錯(cuò)誤的原因。 要修復(fù)錯(cuò)誤,可以將數(shù)組聲明分隔為單獨(dú)的行: echo'
';$ids = array();
希望這可以幫助! You're doing this: echo'
(line 248) '.$ids = array();
Basically, you can'
...
總結(jié)
以上是生活随笔為你收集整理的java array to string_数组到字符串转换(Array to string conversion)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql+create+table+i
- 下一篇: java 16进制与汉字_java实现汉