note 101774 added to function.preg-replace-callback

From: Date: Mon, 10 Jan 2011 22:59:07 +0000
Subject: note 101774 added to function.preg-replace-callback
Groups: php.notes 
Request: Send a blank email to php-notes+get-175613@lists.php.net to get a copy of this message
I needed a simple code to tidy up a string. It simply had to upper-case letters after dot. Simple code to do so: <?php $string = preg_replace_callback( '|(?:\.)(?:\s*)(\w{1})|Ui', create_function('$matches', 'return ". ".strtoupper($matches[1]);'), ucfirst($string) ); ?> <?php $string = 'lorem ipsum dolor sit amet, consectetur adipiscing elit. sed ullamcorper diam eu lorem varius nec porta elit iaculis.'; echo preg_replace_callback( '|(?:\.)(?:\s*)(\w{1})|Ui', create_function('$matches', 'return ". ".strtoupper($matches[1]);'), ucfirst($string) ); ?> Will output: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper diam eu lorem varius nec porta elit iaculis. <?php $string = 'lorem ipsum dolor sit amet, consectetur adipiscing elit. sed ullamcorper diam eu lorem varius nec porta elit iaculis.'; echo preg_replace_callback( '|(?:\.)(?:\s*)(\w{1})|Ui', create_function('$matches', 'return ". ".strtoupper($matches[1]);'), ucfirst($string) ); ?> Will output: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ullamcorper diam eu lorem varius nec porta elit iaculis. Nothing fancy, but useful :) Is there any better solution? ---- Server IP: 82.177.164.100 Probable Submitter: 78.8.134.240 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php Edit -- https://master.php.net/note/edit/101774 Del: integrated -- https://master.php.net/note/delete/101774/integrated Del: useless -- https://master.php.net/note/delete/101774/useless Del: bad code -- https://master.php.net/note/delete/101774/bad+code Del: spam -- https://master.php.net/note/delete/101774/spam Del: non-english -- https://master.php.net/note/delete/101774/non-english Del: in docs -- https://master.php.net/note/delete/101774/in+docs Del: other reasons-- https://master.php.net/note/delete/101774 Reject -- https://master.php.net/note/reject/101774 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175613) next »