How to strip out the IMDB id from a string in php?
I have several thousand text strings where the IMDB occures in fairly random positions, but its always in the following format: tt0234215 (tt + some numbers).
What would be the best way to strip it out in php?
Probably by using a regular expression:
preg_match_all("/tt\\d{7,8}/", $string, $ids);
// $ids will be an array containing the matches
This will search the string for all instances of "tt" followed by exactly seven digits and return them as an array (extra digits will be ignored). (preg_match_all
in the PHP docs)
精彩评论