Reputation: 7390
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/
Upvotes: 1
Views: 97
Reputation: 6036
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!
Upvotes: 2
Reputation: 197659
$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
.
Upvotes: 1
Reputation: 2025
/http:\/\/[\w+-_\.]+\/path\/tt(\d+)\//
Or
~http://[\w+-_\.]+/path/tt(\d+)/~
Upvotes: 0