PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have some code that I cannot make work. It uses PHP to find the words in the <h1> tags in html and then counts the words. However, whenever I run it, no matter how many words are in the <h1> tags, it always returns a "1". I need help to find what is wrong with my code! Any help is appreciated!
Your explode is turning the array into a string ... count() is not for that. Why are you stripping the tags at this step? That should not effect the array count.
I was stripping out the tags to get rid of any html code in the H1 tag. The H1tag in the file we are looking at is as follows: "Web Design & Hosting<br>Locally & Nation Wide". I was hoping to remove the <br>. The count should return the number of words in the tag, but it was returning 1. Now that I tried your suggestion, it returns 2. Why does it not return the correct number? I would like to also like to be able to list the words that it finds in the tag. When I add the following code, I only get the word "array" instead of a list of words.
As I said, count() *does not* work with strings ... only arrays and object properties. http://us3.php.net/count
If the count() function returns 1 it means that the var you gave it is invalid to be counted (hence, not an array or object property). It will only return 0 if the var is NULL.
Sorry, do a print_r($yourarray); and post that here so I can see. And sorry, explode breaks it to an array ... not string. I'll take a look at this some more.