| 
	
 | 
 Posted by Mladen Gogala on 05/11/06 04:03 
On Wed, 10 May 2006 16:43:37 -0700, 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. 
 
Does the following snippet answer your question? 
 
#!/usr/local/bin/php 
<?php 
$buff = "Next Week's Lotto: 123456"; 
if (preg_match("/Next Week's Lotto:\s*(\d+)/", $buff, $hit)) { 
    echo "Next week lottery:", $hit[1], "\n"; 
} else { 
    echo "You suck!\n"; 
}  
?>  
 
 
Of course, I make no claims that the next week's lottery numbers will be 
"123456". No amount of regex massage will help you with that. 
 
--  
http://www.mgogala.com
 
  
Navigation:
[Reply to this message] 
 |