Re: Re: Substr by words

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux