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

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -