PHP str_replace and regexGet the solution ↓↓↓
I am trying by the
preg_replace function to remove the following part of the text string (
/ page / * /), where
* is any number:
/ page / 5 / / page / 10 / / page / 1 / ...
This code is wrong but so that you understand what I want to do
str_replace ('/ page / * /', '', $ string);
In regular expressions,
\d matches a digit, so
\d+ matches a number with any number of digits.
preg_replace(), you have to put delimiters around the regular expression.
$string = preg_replace('#/ page / \d+ /#', '', $string);
People are also looking for solutions of the problem: regex stop at first match
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.