Tuesday, 15 March 2011

php - How to find an occurence in string? -



php - How to find an occurence in string? -

i know best way know if substring in string.

so, can has these kind of value :

"abcd.tif" "abcd_a.tif" "abcd_b.tif" "abcd_vp.tif"

i observe if "_a" or "_b" or "_vp" nowadays in string.

what's best way ? using combination of substr , strlen ?

or utilize regex ?

use strpos, give 0-indexed position of needle in string. if it's not in string, strpos returns false. (there case-insensitive stripos).

however, can check 1 needle @ time. if you'd check of 3 simultaneously can either utilize loop or write terser less efficient way:

preg_match('/_a|_b|_vp/', $str)

...which homecoming true if any of 3 strings matches.

php regex string substring

No comments:

Post a Comment