Answer the question
In order to leave comments, you need to log in
How to remove 8 characters from a link using a regular expression?
I wanted to give links as in this example
to wp-content/uploads/2010/10/DSC_0331z-300×201.jpg
after wp-content/uploads/2010/10/DSC_0331z.jpg
Answer the question
In order to leave comments, you need to log in
<?php
$pattern = "(-\d+x\d+(?=\.(?:jpg|jpeg|png)))";
$subject = "wp-content/uploads/2010/10/DSC_0331z-300x201.jpg wp-content/uploads/2010/10/DSC_ff0331-1920x1080.png";
$replace = "";
echo preg_replace($pattern, $replace, $subject);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question