Let's say I have a string like so:
$file = 'widget-widget-newsletter.php';
I want to use preg_replace() to remove the prefix widget-
and to remove the suffix .php
. Is it possible to use one regular expression to achieve all this?
The resulting string should be widget-newsletter
.
$file = preg_replace('/^widget-|\.php$/', '', $file);
Why not use substr
? Much simpler and faster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With