0

I need a preg_repace function which changes this

http://www.example.org/category/page/14/no/subpage/40/some-address

To this

http://www.example.org/category/page/14/no/some-address

Where 'subpage' is constant and only the number after that is changing. It can be one, two, three or four digit number.

2 Answers 2

1

How about:

$result = preg_replace('~subpage/[^/]+/~', '', $str);

or:

$result = preg_replace('~subpage/\d{1,4}/~', '', $str);
Sign up to request clarification or add additional context in comments.

Comments

1
$url = preg_replace('#subpage/\d+#', '', $url);

\d matches a digit, and + matches 1 or more of them.

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.