how to convert permalink
'watch.php?a=RANDOMTEXT1&e=RANDOMTEXT2'
to
'watch/a/RANDOMTEXT1/e/RANDOMTEXT2.html'
with php preg_replace if RANDOMTEXT1 and RANDOMTEXT2 is random text?
how to convert permalink
'watch.php?a=RANDOMTEXT1&e=RANDOMTEXT2'
to
'watch/a/RANDOMTEXT1/e/RANDOMTEXT2.html'
with php preg_replace if RANDOMTEXT1 and RANDOMTEXT2 is random text?
You could use e.g. this regex:
(watch)\.php\?(a)=([^&]+)&(e)=([^&]+)
And replace it with:
$1/$2/$3/$4/$5.html
But it really depends on your requirements. Is this the only example where you need to create a link like this? You could also simplify the regex and only use watch\.php\?a=([^&]+)&e=([^&]+)
and replace it with watch/a/$1/e/$2.html
. If you want the regex to also allow &
character, but only if they are not followed by an equal sign =
, you would need to use negative lookaheads.
Here is the live example: https://regex101.com/r/jdRaok/1