note 39707 added to function.preg-replace

From: Date: Sun, 08 Feb 2004 08:19:10 +0000
Subject: note 39707 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-64811@lists.php.net to get a copy of this message
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 ?> ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39707 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39707&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39707&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64811) next »