【发布时间】:2016-07-25 06:44:32
【问题描述】:
我的代码有问题。我正在为我的项目使用 curl。所有需要的数据都正确获取,但保存过程开始时出现问题。
$SizeParag = sizeof($dr_match[0]);
for($CountParag=1;$CountParag<$SizeParag;$CountParag++) {
$description = ($dr_match[0][$CountParag]);
}
我正在使用此代码获取所有段落,但问题是当我保存字符串 $description 时,它只保存最后一段。
在保存之前我应该如何保存所有 $description 的值。提前感谢您对我的帮助。
【问题讨论】:
-
$description = array();$SizeParag = sizeof($dr_match[0]); for($CountParag=1;$CountParag<$SizeParag;$CountParag++){ $description[] = ($dr_match[$CountParag][$CountParag]); } -
感谢您的回复。但是当我尝试代码时,它只能保存单词 Array.
-
抱歉
$dr_match[$CountParag]不是$dr_match[$CountParag][$CountParag]。也可以显示echo "<pre/>";print_r($dr_match); -
请使用
echo "<pre/>";print_r($dr_match);显示$dr_match中有什么值 -
注意:Undefined offset: 8 in C:\xampp\htdocs\politicscurl.php 上线(其中$description[] =($dr_match[$CountParag++); 写成只能保存而已描述的单词数组。