Other mistake in my last script.
Gustavo Narea wrote:
<?php
$MyOriginalString = "This is my original string.\nWhat do you think
about this script?";
$MaxWords = 6; // How many words are needed?
$replacement = preg_match("/^(\W*\b\w+\b){1,$MaxWords}/", '',
$MyOriginalString);
$result = substr( $MyOriginalString, 0, ($replacement) ?
-strlen($replacement) : strlen($MyOriginalString));
echo $result;
?>
Instead of preg_match(), I had to type preg_replace():
<?php
$MyOriginalString = "This is my original string.\nWhat do you think
about this script?";
$MaxWords = 6; // How many words are needed?
$replacement = preg_replace("/^(\W*\b\w+\b){1,$MaxWords}/", '',
$MyOriginalString);
$result = substr( $MyOriginalString, 0, ($replacement) ?
-strlen($replacement) : strlen($MyOriginalString));
echo $result;
?>
Best regards,
Gustavo Narea.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php