this is my string: http://www.something.com/path/tt0425235/somethingelse/
and i need to get just "0425235" (Beetween "tt" and "/")
Test with:http://rubular.com/
Simple and perfect ;)
<?php
$match = array();
$url = 'http://www.something.com/path/tt0425235/somethingelse/bla/bla/bla/bla/?bla=bla';
preg_match( '/\/path\/([a-z]+([\d]+))+\/?/i' , $url , $match );
print_r( $match );
?>
Bye!
#http://www\.imdb\.com/title/tt(\d+)/#
/http:\/\/[\w+-_\.]+\/path\/tt(\d+)\//
Or
~http://[\w+-_\.]+/path/tt(\d+)/~
$url = 'http://www.something.com/path/tt0425235/';
list($id) = preg_split('~^.*/tt(\d+)/$~', $url, 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY) + array(NULL);
If it can't find your pattern, $id
will be NULL
.