How to get all array values in php? -
i've been trying create new pages using template strings in replaced values arrays. page creation working fine specific array number. however, i'm expecting create new pages values arrays, not 1 or 2 specific value.
this code far:
<?php $dom= file_get_html($url); $array_title = array(); $array_details = array(); foreach ($dom->find('div[class=main]') $results) { foreach ($results->find('title') $title) { $array_title[] = $title->alt; } foreach ($results->find('div[class=details]') $details) { $array_descript[]= $details->innertext; } } { $page = str_replace("{title}", $array_title[3], $template); $page = str_replace("{descript}", $array_descript[3], $page); //create name new page $pagename = $array_title[3].".php"; //put created content file file_put_contents("article/".$pagename,$page); } ?>
the arrays when echoed:
array ( [0] => guacamole [1] => buffalo chicken dip [2] => jalapeno popper spread [3] => 7 layer taco dip [4] => brown sugar smokies [5] => baked kale chips ) array ( [0] => guacamole recipe [1] => buffalo chicken dip recipe [2] => jalapeno popper spread recipe [3] => 7 layer taco dip recipe [4] => brown sugar smokies recipe [5] => baked kale chips recipe )
the code above created new page values in 3rd row arrays. i've tried make array number blank [ ]
, returned following error: php fatal error: cannot use [ ] reading
.
may insight array values i'm expecting? in advance
heres code above changes suggesting you:
<?php $dom= file_get_html($url); $array_title = array(); $array_details = array(); foreach ($dom->find('div[class=main]') $results) { foreach ($results->find('title') $title) { $array_title[] = (string)$title->alt; } foreach ($results->find('div[class=details]') $details) { $array_descript[]= (string)$details->innertext; } } { $page = str_replace("{title}", $array_title[3], $template); $page = str_replace("{descript}", $array_descript[3], $page); //create name new page $pagename = $array_title[3].".php"; //put created content file file_put_contents("article/".$pagename,$page); } ?>
Comments
Post a Comment