php - Pregmatch and count giving bad result -


I am trying to get all the occurrences of regular expressions using preg_match_all and then there are specific strings in those events. or not. After that, I am trying to compute and compare numbers but I think it is not working. I am working with the HTML data taken from the database, and yes, I need regular expressions for HTML. Any data I get from a database, the result is as follows: Image pregme number: 2Image search count: 1Table pregmatch count: 2Table search count: 1

This is my code snippet :

  $ query = $ DB- & gt; Get_field ('book_chapters', 'content', array ('bookid' = & gt; '1')); $ Img_pat = '/<img(.*)\>/i'; // regular expression for image tag search $ table_pat = '/<tabletable.edu.exe; // regular expression for table tag search query echo $ query; $ content = serialize ($ query); Counterpart $ content; // image preg_match_all ($ img_pat, $ content, $ img_pregmatch); $ Img_search = array_search ('alt =' ', $ img_pregmatch);' Image pregme count: '. Count ($ img_pregmatch); Echo 'image search count:' count ($ img_search); // table preg_match_all ($ table_pat), $ content, $ table_pregmatch); $ table_search = array_search ('summary =' ', $ table_pregmatch); Count echo 'table pregmatch:' Count ($ table_pregmatch); Echo 'table search count:'. Count ($ table_search);   

And this example is when using rubular.com

rubular.com example

Any help, advice is appreciated, thanks!

preg_match_all () will return an array of capture groups, then $ Img_pregmatch [0] will have all your matches and will return $ img_pregmatch [1] to your first capture groups.

Try to change your matters:

  'Image pregme number:' echo count ($ img_pregmatch [0]); Count echo 'table pregmatch:' Count ($ table_pregmatch [0]);  

Note:

You should not use it because HTML is not an regular language .

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -