sandy1028 Posted April 29, 2009 Share Posted April 29, 2009 Hi, I have a file contents in a file. $data=file('myfile.txt'); From this I have to grep for the strings between "Results" and "seconds". Quote Link to comment https://forums.phpfreaks.com/topic/156107-grep/ Share on other sites More sharing options...
Ken2k7 Posted April 29, 2009 Share Posted April 29, 2009 From what I know, you'll probably want to loop through $data and use preg_match or preg_match all. I think this RegExp should work: Results(.*?)seconds Edit: not sure if there are spaces between Results and seconds. You probably want to include spaces. But again, you haven't told me much. Also, http://www.phpfreaks.com/forums/index.php/topic,250066.0.html. That's your other topic. Same thing. You can use the same RegExp for this with a few changes. Quote Link to comment https://forums.phpfreaks.com/topic/156107-grep/#findComment-821866 Share on other sites More sharing options...
sandy1028 Posted April 30, 2009 Author Share Posted April 30, 2009 <p> Results <b>1</b> - <b>10</b> of about <b>87,800,000</b> for <b>aaa</b> [<a href="/url?q=http://www.answers.com/aaa&r=67&ei=VCn5ScLKCtWGkAWmmM2LCg&sa=X&oi=dict&ct=d&usg=AFQjCNHhNb5eNJ7HxcW4GRMeBmfbiYe5cw" title="Look up definition of aaa">definition</a>]<b></b>. (<b>0.08</b> seconds) </div><div id=res class=med><!--a--><h2 class=hd>Search Results</h2><div><ol><!--m--><link rel="prefetch" href="http://www.aaa.com/"><li class=g><h3 class=r> <a href="http://www.aaa.com/" class=l onmousedown="return clk(this.href,'','','res','1','')"><em>AAA</em> - How to extract only the string between Results and from seconds and delete the other characters. Quote Link to comment https://forums.phpfreaks.com/topic/156107-grep/#findComment-822437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.