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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -