Wednesday 15 January 2014

php - Return number after an underscore, dynamic preceeding -


I have different values ​​in the PHP array, which are given below:

  $ Value = array ("News_24", "news_81", "blog_56", "member_55", "news_27");   

The first part of the pre-underscore ( news, blog, member ) is dynamic, so I would like to receive all the matches in a specific section ( < / P>

$ section = "news";

$ Matches = preg_match ('$ section / [_]) GETNUMBER /', $ value);

This 24 and 27 will return, but only where the news was before the underscore.

Thank you.

$ value = array ("news_4", "news_81", "blog_56", "Member_55", "news 77"); $ Section = "news"; Forex currency ($ value $ value) {$ matches = preg_match ("/ {$ section} _ (\\ d +) /", $ value, $ number); If ($ matches) echo $ $ number [1], PHP_EOL; }

No comments:

Post a Comment