You are here: Re: grab succeeding string « PHP Programming Language « IT news, forums, messages
Re: grab succeeding string

Posted by Rik on 05/11/06 03:27

strawberry wrote:
> Say I have a chunk of text and I know that somewhere in that chunk ot
> text is the phrase 'Next Week's Winning Number will be:', is there a
> way I can automatically grab the string immediately following?
>
> Any help greatly appreciated.


If you know the stringlength of the following string:

$occurance = strpos( $chunk, 'Next Week's Winning Number will be:');
$occurance += strlen('Next Week's Winning Number will be:');
$string = trim(substr($occurance, $lenght_of_searched_string));

If the lenght is undefined, use slower regular expression (allthough added
bonus is we can filter out whitespace-characters):

preg_match("/(?<=Next Week's Winning Number will be:)\s*([^\s]+?)\b/si",
$chunk, $match);
$string=$match[1];

Grtz,
--
Rik Wasmus

 

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

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