note 39707 deleted from function.preg-replace by irchtml

From: Date: Sun, 08 Feb 2004 08:26:20 +0000
Subject: note 39707 deleted from function.preg-replace by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64812@lists.php.net to get a copy of this message
Note Submitter: silasjpalmer@.optusnet.com.au ---- Here's a little routine to quote an extract from a string. It will quote up to the first 100 characters, but won't break the middle of a word. <?php $string = "verylongword1 verylongword2 verylongword3 verylongword4 verylongword5 verylongword6 verylongword7 verylongword8 verylongword9 verylongword10 verylongword11 verylongword12 verylongword13"; $pattern = "/^(.{1,100}) (.*$)/"; $replacement = "\${1}"; echo preg_replace($pattern, $replacement, $string); // Returns verylongword1 verylongword2 verylongword3 // verylongword4 verylongword5 verylongword6 verylongword7 ?>

« previous php.notes (#64812) next »