943,865 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 651
  • PHP RSS
Sep 8th, 2009
0

Display Number of Times X Value is Empty

Expand Post »
Hello,

I am retrieving results from a RSS feed, but not all results have a title. I would like to run something like the below code which, lets me know how many times a title is empty.

If three "titles" are empty, then X code would dynamically echo "3" etc....

Not sure if a foreach would work... Thanks in advance!

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. if(empty($title)){
  3. //Code for displaying how many times "$title" is empty
  4.  
  5. } else {
  6.  
  7. echo $title;
  8.  
  9. }
  10. ?>
Similar Threads
Reputation Points: 20
Solved Threads: 0
Light Poster
lonestar23 is offline Offline
43 posts
since Mar 2008
Sep 8th, 2009
1

Re: Display Number of Times X Value is Empty

So is $title the title of a single RSS feed item? If so, you can do something like:
php Syntax (Toggle Plain Text)
  1. $count = 0;
  2. foreach($rssFeedItems as $title)
  3. {
  4. if(empty($title))
  5. echo ++$count; // a prepend increment will add one to $count before it is used
  6. else
  7. echo $title;
  8. }
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: problem to create input text continiously?
Next Thread in PHP Forum Timeline: sql syntax issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC