0

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.

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

you could try a pattern like this:

"/(.*)\/([^/])*\/(.*)/"

and then with str_replace you can: $string = str_replace('/'.$matches[2], '', $string);

Comments

0
preg_replace("|file/\w+/|", "file/", $url);

This will search for 1st pattern between "/" symbols just after "file/" part.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.