note 101296 added to function.preg-replace

From: Date: Wed, 08 Dec 2010 18:30:24 +0000
Subject: note 101296 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-174713@lists.php.net to get a copy of this message
I find it useful to output HTML form names to the user from time to time while going through the $_GET or $_POST on a user's submission and output keys of the GET or POST array... the only problem being in the name attribute I follow common programming guidelines and have names like the following: eventDate, eventTime, userEmail, etc. Not great to just output to the user-- so I came up with this function. It just adds a space before any uppercase letter in the string. function caseSwitchToSpaces( $stringVariableName ) { $pattern = '/([A-Z])/'; $replacement = ' ${1}'; return preg_replace( $pattern, $replacement, $stringVariableName ); } ex. echo( caseSwitchToSpaces( "helloWorld" ) ); would output: "hello World" You could also do title-style casing to it if desired so the first word isn't lowercase. ---- Server IP: 69.147.83.197 Probable Submitter: 69.4.36.98 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/101296 Del: integrated -- https://master.php.net/note/delete/101296/integrated Del: useless -- https://master.php.net/note/delete/101296/useless Del: bad code -- https://master.php.net/note/delete/101296/bad+code Del: spam -- https://master.php.net/note/delete/101296/spam Del: non-english -- https://master.php.net/note/delete/101296/non-english Del: in docs -- https://master.php.net/note/delete/101296/in+docs Del: other reasons-- https://master.php.net/note/delete/101296 Reject -- https://master.php.net/note/reject/101296 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174713) next »