开发者

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜