Demonic Posted March 30, 2007 Share Posted March 30, 2007 Alright I got this array right: Array ( [0] => Array ( [0] => <title>W3Schools Home Page</title> [1] => <title>RSS Tutorial</title> [2] => <title>XML Tutorial</title> ) [1] => Array ( [0] => W3Schools Home Page [1] => RSS Tutorial [2] => XML Tutorial ) [2] => Array ( [0] => <link>http://www.w3schools.com</link> [1] => <link>http://www.w3schools.com/rss</link> [2] => <link>http://www.w3schools.com/xml</link> ) [3] => Array ( [0] => http://www.w3schools.com [1] => http://www.w3schools.com/rss [2] => http://www.w3schools.com/xml ) [4] => Array ( [0] => <description>Free web building tutorials</description> [1] => <description>New RSS tutorial on W3Schools</description> [2] => <description>New XML tutorial on W3Schools</description> ) [5] => Array ( [0] => Free web building tutorials [1] => New RSS tutorial on W3Schools [2] => New XML tutorial on W3Schools ) ) So im trying combine them together using foreach for each section whats best way to do this? I want the outcome to be as follows: W3Schools Home Page : http://www.w3schools.com : Free web building tutorials New RSS Tutorial : http://www.w3schools.com/rss : New RSS tutorial on W3Schools New XML Tutorial : http://www.w3schools.com/xml : New XML tutorial on W3Schools Whats best way to do this? How I got that array: <?php $file = "rssfeeder-test.xml"; $size = filesize($file); $rss = file_get_contents($file,$size); //echo ("<textarea cols='40' rows='40'>$rss</textarea>\n"); preg_match_all("/\<title\>(.*)\<\/title\>/i",$rss,$title); preg_match_all("/\<link\>(.*)\<\/link\>/i",$rss,$link); preg_match_all("/\<description\>(.*)\<\/description\>/i",$rss,$desc); $result = array_merge_recursive($title,$link,$desc); print_r($result); ?> http://www.uni-code.com/codebox/rssfeeder-test2.php Quote Link to comment Share on other sites More sharing options...
Barand Posted March 30, 2007 Share Posted March 30, 2007 <?php $data = Array ( 0 => Array ( 0 => '<title>W3Schools Home Page</title>', 1 => '<title>RSS Tutorial</title>', 2 => '<title>XML Tutorial</title>' ), 1 => Array ( 0 => 'W3Schools Home Page', 1 => 'RSS Tutorial', 2 => 'XML Tutorial' ), 2 => Array ( 0 => '<link>http://www.w3schools.com</link>', 1 => '<link>http://www.w3schools.com/rss</link>', 2 => '<link>http://www.w3schools.com/xml</link>' ), 3 => Array ( 0 => 'http://www.w3schools.com', 1 => 'http://www.w3schools.com/rss', 2 => 'http://www.w3schools.com/xml' ), 4 => Array ( 0 => '<description>Free web building tutorials</description>', 1 => '<description>New RSS tutorial on W3Schools</description>', 2 => '<description>New XML tutorial on W3Schools</description>' ), 5 => Array ( 0 => 'Free web building tutorials', 1 => 'New RSS tutorial on W3Schools', 2 => 'New XML tutorial on W3Schools' ) ); for ($i=0; $i<3;$i++) { echo strip_tags($data[0][$i]), ' : ', $data[3][$i], ' : ', $data[5][$i], '<br>'; } ?> Quote Link to comment Share on other sites More sharing options...
Demonic Posted March 30, 2007 Author Share Posted March 30, 2007 Nice one. imma give that a try. Quote Link to comment Share on other sites More sharing options...
Demonic Posted March 30, 2007 Author Share Posted March 30, 2007 Quick question there wont be just 3 titles what would I do then? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 30, 2007 Share Posted March 30, 2007 <?php $k = count($data[0]); for ($i=0; $i<$k; $i++) { echo strip_tags($data[0][$i]), ' : ', $data[3][$i], ' : ', $data[5][$i], '<br>'; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.