note 40925 deleted from function.preg-replace by colder

From: Date: Mon, 18 Jun 2007 19:51:04 +0000
Subject: note 40925 deleted from function.preg-replace by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127668@lists.php.net to get a copy of this message
Note Submitter: silasjpalmer at optusnet dot com dot au ---- Using preg_rep to return extracts without breaking the middle of words (useful for search results) <?php $string = "Don't split words"; echo substr($string, 0, 10); // Returns "Don't spli" $pattern = "/(^.{0,10})(\W+.*$)/"; $replacement = "\${1}"; echo preg_replace($pattern, $replacement, $string); // Returns "Don't" ?>

« previous php.notes (#127668) next »