You are here: Re: [PHP] Re: Substr by words « PHP « IT news, forums, messages
Re: [PHP] Re: Substr by words

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация