desmondMorris Posted February 23, 2010 Share Posted February 23, 2010 hi i am using the following code: if(preg_match_all('%read (?P<words>\w+)%i', $text, $out)) {... i want to be able to print whatever is written aftet the word 'read' is used, this is working fine so far, however currently only the first word after 'read' is being printed. i want to be able to print the whole line, up until a ';' is seen. does anyone have any ideas on this? cheers in advance des. Quote Link to comment https://forums.phpfreaks.com/topic/193098-reading-in-and-stopping/ Share on other sites More sharing options...
mikesta707 Posted February 23, 2010 Share Posted February 23, 2010 Can you give us an example line that will be read? your regex looks a little off Quote Link to comment https://forums.phpfreaks.com/topic/193098-reading-in-and-stopping/#findComment-1016904 Share on other sites More sharing options...
desmondMorris Posted February 23, 2010 Author Share Posted February 23, 2010 text is input into a form, when its submitted, wherever the word 'read' is found, the next word is printed. it works fine. this is the full code ive got: <?php if(isset($_POST['submit'])){ $text = $_POST['txt']; if(preg_match_all('%read (?P<words>\w+)%i', $text, $out)) { $words = $out['words']; } //echo '<pre>'.print_r(get_defined_vars(), true).'</pre>'; if(isset($words)) { $arrayAmount = count($words); for ($i=0;$i<=$arrayAmount;$i++){ echo "$words[$i]\n"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/193098-reading-in-and-stopping/#findComment-1016907 Share on other sites More sharing options...
desmondMorris Posted February 23, 2010 Author Share Posted February 23, 2010 also how would i make it so words in double quotes are also printed, they seem to get skipped. cheers Quote Link to comment https://forums.phpfreaks.com/topic/193098-reading-in-and-stopping/#findComment-1016915 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.