Hi,
I'm trying to preg_replace charset=blablabla;
and charset=blablabla"
with charset=utf-8;
and charset=utf-8"
. Please see ;
=
and "
characters, and of course searched string can be lower/uppercase.
Can you help me?
Hi,
I'm trying to preg_replace charset=blablabla;
and charset=blablabla"
with charset=utf-8;
and charset=utf-8"
. Please see ;
=
and "
characters, and of course searched string can be lower/uppercase.
Can you help me?
You could try something like this.
echo preg_replace("#charset=[a-zA-Z0-9]+(\;)?#", "charset=utf-8$1", "charset=sdfsfsds");
You could replace the value with something like:
$subject = 'Testing... charset=baz; and charset=bat" :-)';
echo preg_replace('/(?<=charset=)[a-zA-Z0-9_-]+(?=[;"])/', 'utf-8', $subject);
// Testing... charset=utf-8; and charset=utf-8" :-)
Deconstructed, the regex matches:
charset=
(using a lookbehind)