|
Posted by Gustavo Narea on 10/30/05 18:51
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.
Navigation:
[Reply to this message]
|