Modernvox Posted December 30, 2009 Share Posted December 30, 2009 Hi guys, I have this code, but it is not returning the values as I had planned. It shows the title as a local link only and doesn't show more than 2 posts at a time. Here is the output i am getting: Violin and Voice Lessons - (ri)Small Band Practice Space - (Olneyville)/muc/1530263612.html/muc/1530038374.htmlViolin and Voice Lessons -Small Band Practice Space - (ri) (Olneyville) Here is the expected output:<(note: titles should be a link like on Craigslist. D R U M_L E S S O N S>>>>with mike levesque - (RI/MA) Violin and Voice Lessons - (ri) Godsmack tribute"moonbaby" seeks sully - (ri) Huge Band Practice Space - (Olneyville) Small Band Practice Space - (Olneyville) <?php $html = file_get_contents("http://southcoast.craigslist.org/muc/"); preg_match_all('/<a href="([^"]+)">([^<]+)<\/a><font size="-1">([^"]+) <\/font>/', $html,$posts); foreach ($posts as $post) { echo $post[1]; $title = $post[2]; $date = $post[3]; echo $content = $post[4]; // do something with data } ?> Quote Link to comment https://forums.phpfreaks.com/topic/186711-array-returning-weird-values/ Share on other sites More sharing options...
rajivgonsalves Posted December 30, 2009 Share Posted December 30, 2009 try this for the match preg_match_all('/<a href="([^"]+)">([^<]+)<\/a><font size="-1">([^"]+)<\/font>/s', $html,$posts); Quote Link to comment https://forums.phpfreaks.com/topic/186711-array-returning-weird-values/#findComment-986051 Share on other sites More sharing options...
Modernvox Posted December 30, 2009 Author Share Posted December 30, 2009 Displayed like such: Band needed for NY's Eve - (RI)Violin and Voice Lessons - (ri)/muc/1530332391.html/muc/1530263612.htmlBand needed for NY's Eve -Violin and Voice Lessons - (RI) (ri) It's just not displaying properly. Should be displaying in similar format as craigslist itself http://providence.craigslist.org/muc/ Quote Link to comment https://forums.phpfreaks.com/topic/186711-array-returning-weird-values/#findComment-986064 Share on other sites More sharing options...
Modernvox Posted December 30, 2009 Author Share Posted December 30, 2009 I have it displaying: Band needed for NY's Eve - (RI)/muc/1530332391.htmlBand needed for NY's Eve - (RI) Notice it is being repeated? /muc/1530332391.htmlBand needed for NY's Eve - (RI) I need to get rid of the extra post. Also it is only displaying the first one. I need at least 30 to display. Finally, the link is suppose to link back to craigslist , but it links to my localhost? Quote Link to comment https://forums.phpfreaks.com/topic/186711-array-returning-weird-values/#findComment-986070 Share on other sites More sharing options...
Modernvox Posted December 30, 2009 Author Share Posted December 30, 2009 Still waiting Quote Link to comment https://forums.phpfreaks.com/topic/186711-array-returning-weird-values/#findComment-986095 Share on other sites More sharing options...
rajivgonsalves Posted December 31, 2009 Share Posted December 31, 2009 not to sure how you want the content but I came up with this <?php $html = file_get_contents("http://southcoast.craigslist.org/muc/"); preg_match_all('/<h4>(.*?)<\/h4>|<a href="([^"]+)">([^<]+)<\/a><font size="-1">([^"]+)<\/font>/s', $html,$posts); $content = array(); $cur_date = ''; for ($i=0;$i < count($posts[0]);$i++) { if (date("D M d", strtotime($posts[1][$i])) == $posts[1][$i]) { $cur_date = $posts[1][$i]; continue; } $content[] = array('date' => $cur_date, 'href' => $posts[2][$i], 'content' => $posts[3][$i], 'location' => $posts[4][$i]); // do something with data } print_r($content); ?> Quote Link to comment https://forums.phpfreaks.com/topic/186711-array-returning-weird-values/#findComment-986325 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.