Reputation: 159
I have a problem with preg_match in PHP.
I have URLs:
http://mysite.com/file/w867/2612512232
http://mysite.com/file/c3233/2123255464
etc.
I need URLs:
http://mysite.com/file/2612512232
http://mysite.com/file/2123255464
I must remove:
w867/
c3233/
etc.
Upvotes: 0
Views: 1123
Reputation: 2576
preg_replace("|file/\w+/|", "file/", $url);
This will search for 1st pattern between "/" symbols just after "file/" part.
Upvotes: 0
Reputation: 633
You don't necessarily need to use preg_match. parse_url() can do the job.
http://us.php.net/manual/en/function.parse-url.php
Just make sure to concatenate it all against without the part you don't want.
Upvotes: 2
Reputation: 2610
you could try a pattern like this:
"/(.*)\/([^/])*\/(.*)/"
and then with str_replace you can: $string = str_replace('/'.$matches[2], '', $string);
Upvotes: 0