php - Replace an upper-case string with lower-case using preg_replace() and regex -
is possible replace upper-case lower-case using preg_replace , regex?
for example:
the following string:
$x="hello ladies!"; i want convert to:
hello ladies! using preg_replace():
echo preg_replace("/([a-z]+)/","$1",$x);
i think trying accomplish:
$x="hello ladies! test"; echo preg_replace_callback('/\b([a-z]+)\b/', function ($word) { return strtolower($word[1]); }, $x); output:
hello ladies! test regex101 demo: https://regex101.com/r/td7si0/1
if want whole string lowercase though use strtolower on whole thing.
Comments
Post a Comment