0

How to use the preg_replace function to replace

/c83403.403/

Example: https://startimage.ca/c83403.403/ahmedmynewpix.jpg

another example: https://startimage.ca/c2.3403.403/ahmedmynewpix2.jpg

It always start with /c..../ I want to replace that with ""

I am trying the following but not working $str = '/c..../'; $str = preg_replace('/+[0-9]', '', $str);

1 Answer 1

2

Do you mean something like this?

$str = 'https://startimage.ca/c83403.403/ahmedmynewpix.jpg';
$str = preg_replace('|/c[0-9.]+|', '', $str);
echo $str; # https://startimage.ca/ahmedmynewpix.jpg'

... or

$str = preg_replace('|/c[0-9.]+|', '/c', $str);
echo $str; # https://startimage.ca/c/ahmedmynewpix.jpg'

The point is that you replace anything starting from /c and containing either digits or dot symbol (.) - with either empty space or /c string, depending on what you need. )

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

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.