Reputation: 6436
What is the best solution to extract the name of the movie or TV serie from this path; E:\Dropbox\Hemsidor\collection-test\movies\avatar\documents\actors.txt
?
I have checked explode
but that solution are just annoying if you have to split every /
from the path.
EDIT
The search can result in more than one hits. The results can be displayed as this:
E:\Dropbox\Hemsidor\collection-test\movies\avatar\documents\actors.txt
E:\Dropbox\Hemsidor\collection-test\movies\the_butterfly_effect\documents\actors.txt
How can I loop the titles?
Thanks in advance.
Upvotes: 1
Views: 114
Reputation: 15044
$string = 'E:\Dropbox\Hemsidor\collection-test\movies\avatar\documents\actors.txt?';
preg_match('/\\\movies\\\([^\x5C]+)/', $string, $matchs);
echo $matchs[1];
Upvotes: 2
Reputation: 57690
You dont need Regex for this simple search. In fact RegEx is slower for large scale data. Following code will do it perfectly
$string = 'E:\Dropbox\Hemsidor\collection-test\movies\avatar\documents\actors.txt?';
$a = explode('\\', $string);
echo $a[array_search('movies', $a)+1];
Upvotes: 1