note 101296 deleted from function.preg-replace by cmb

From: Date: Sun, 22 Sep 2019 08:02:16 +0000
Subject: note 101296 deleted from function.preg-replace by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212307@lists.php.net to get a copy of this message
Note Submitter: ude dot mpco at wotsrabt dot maps-on ---- 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. <?php 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.

« previous php.notes (#212307) next »