mraza Posted November 15, 2010 Share Posted November 15, 2010 hi i am stuck in a loop please can someone check what is miss. I wants to quit from loop and go to next title if that tile is found but cant figure out how should i go. my code: $feed_url = "http://www.myfeed.com/feed/"; $xml = simplexml_load_file($feed_url); foreach ($xml->channel->item as $item) { $ns_content = $item->children('http://purl.org/rss/1.0/modules/content/'); $title = $item->title; // opening file which contain titles already $content = file('file.txt'); foreach ($content as $aline) { if (strstr($title, $aline)) { $found = true; } } // i dont wants to print that $title which is already in file.txt so loop continue. if($found) { continue; } echo $title . "<br>" ; } Problem is with that continue statement if a title is matched from file.txt it will display me nothing, i only wants to skip that title and echo other titles. thanks for any help Link to comment https://forums.phpfreaks.com/topic/218736-continue-loop/ Share on other sites More sharing options...
BlueSkyIS Posted November 15, 2010 Share Posted November 15, 2010 what results are you currently getting? what's wrong? Link to comment https://forums.phpfreaks.com/topic/218736-continue-loop/#findComment-1134471 Share on other sites More sharing options...
mraza Posted November 15, 2010 Author Share Posted November 15, 2010 if a title is matched from file.txt it does not display any result, it shows a blank page, i wants it like if a title is matched it will skip that title and display other. Link to comment https://forums.phpfreaks.com/topic/218736-continue-loop/#findComment-1134473 Share on other sites More sharing options...
AbraCadaver Posted November 15, 2010 Share Posted November 15, 2010 There are better ways to do this, if the titles are actually identical then it will be even easier, but your problem is that once $found is set to true it is always true. You need to set it to false at the beginning of the loop somewhere. Link to comment https://forums.phpfreaks.com/topic/218736-continue-loop/#findComment-1134474 Share on other sites More sharing options...
mraza Posted November 15, 2010 Author Share Posted November 15, 2010 thanks but it is not showing anything either $found = false; foreach ($xml->channel->item as $item) { $ns_content = $item->children('http://purl.org/rss/1.0/modules/content/'); $title = $item->title; $content = file('file.txt'); foreach ($content as $aline) { if (strstr($title, $aline)) { $found = true; } } if($found){ continue; } echo $title . "<br>" ; } it display only a blank page. if i remove continue; it shows me all titles from feed without problem. in my file.txt all titles are on a new line so are identical. Link to comment https://forums.phpfreaks.com/topic/218736-continue-loop/#findComment-1134483 Share on other sites More sharing options...
AbraCadaver Posted November 15, 2010 Share Posted November 15, 2010 foreach ($xml->channel->item as $item) { $found = false; But like I said if the titles are identical then this is easier and faster: $feed_url = "http://www.myfeed.com/feed/"; $xml = simplexml_load_file($feed_url); $content = file('file.txt'); foreach ($xml->channel->item as $item) { $title = $item->title; if(!in_array($title, $content)) { echo $title; } } Link to comment https://forums.phpfreaks.com/topic/218736-continue-loop/#findComment-1134489 Share on other sites More sharing options...
mraza Posted November 15, 2010 Author Share Posted November 15, 2010 hm thanks again sir but for some reason !in_array is also not working properly, if there is title in file it still display title with above code. in my other script what i do is run the script and save that title of feed in a file here is code $ourFileName = "file.txt"; $ourFileHandle = fopen($ourFileName, 'a') or die("can't open file"); fwrite($ourFileHandle, "$title\n"); fclose($ourFileHandle); so it save that title in file.txt so next time when i run above script it should not read that feed again which has same title in file.txt, is there are any other thing i can try? thanks again Link to comment https://forums.phpfreaks.com/topic/218736-continue-loop/#findComment-1134566 Share on other sites More sharing options...
AbraCadaver Posted November 15, 2010 Share Posted November 15, 2010 You can try this. If it doesn't work then that means they are not identical: $content = file('file.txt', FILE_IGNORE_NEW_LINE); Link to comment https://forums.phpfreaks.com/topic/218736-continue-loop/#findComment-1134585 Share on other sites More sharing options...
mraza Posted November 15, 2010 Author Share Posted November 15, 2010 thank you very much sir this works $content = file('file.txt', FILE_IGNORE_NEW_LINE | FILE_SKIP_EMPTY_LINES); thx Link to comment https://forums.phpfreaks.com/topic/218736-continue-loop/#findComment-1134607 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.