Jump to content

finding values within strings


real_illusions

Recommended Posts

Hi all,I have an array of certain words and I want to see how many times they are used within a string.Was thinking of the strpos() function, but that only returns the first instance of a word/value within the string.Is there an easy way of doing this?

Link to comment
Share on other sites

Cant quite get my head round RegEx.Basically need a way of finding how many heading tags are on a web page (<h1> thru to <h6>.Would a regex pattern like this "h.[1-6]" do the trick or is that completely in the wrong direction?

Link to comment
Share on other sites

To avoid matching literal text that says "h6", you might want to include at least the "<" in your regex, like:

$pattern = "/\<(h1|h2|h3|h4|h5|h6)/";

But keep in mind the $headings array would be altered a little by that change. Make sure you count it properly (var_dump it, inspect it... you'll see).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...