arrays - Get word from string - PHP -


i trying extract word matches specific pattern various strings.

the strings vary in length , content.

for example:

i want extract word begins jac following strings , populate array full words:

  • i bought jacket yesterday.
  • jack going home.
  • i want go jacksonville.

the resulting array should [jacket,jack,jacksonville]

i have been trying use preg_match() reason won't work. suggestions???

$q = "jac"; $str = "jacket"; preg_match($q,$str,$matches);  print $matches[1]; 

this returns null :s. dunno problem is.

you can use preg_match as:

preg_match("/\b(jac.+?)\b/i", $string, $matches); 

see it


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -