...

View Full Version : extract specific words out of a string



kamkam
11-12-2011, 02:11 AM
Hi;

How could i extract specific words out of a string and put into an array, please.

Eg;
$string="talking animails and get rid off talking about this facebook";
$term="talking a";

The final result will be:

$final[]="talking animails, talking about ",

MattF
11-12-2011, 04:13 AM
<?php

$string = 'talking animails and get rid off talking about this facebook';
$regex = '~talking a[\w]+~im';

preg_match_all($regex, $string, $matches);

print_r($matches[0]);

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum