Match Phrases (in array) in text string

Posted by Tim Hanssen on Stack Overflow See other posts from Stack Overflow or by Tim Hanssen
Published on 2013-06-24T21:58:12Z Indexed on 2013/06/24 22:21 UTC
Read the original article Hit count: 118

Filed under:
|
|

I'm using the Twitter API streaming to collect thousand of tweets every minute. They need to be matched to a list of keywords (can contain spaces).

This is my current method:

$text = preg_replace( '/[^a-z0-9]+/i', ' ', strtolower( $data['text'] ) );
$breakout = explode( " ", $text );

$result = array_intersect( $this->_currentTracks, $breakout );

I chop the tweet into words, and the matches them against my current keywords. This works well for all the keywords without a space ofc.

If I wanted to find for example "Den Haag", It won't show up, because the string is exploded into words (based on the spaces).

Any ideas about how I can do this in a quick way?

Kind regards, Tim

© Stack Overflow or respective owner

Related posts about php

Related posts about regex