desmondMorris Posted January 8, 2010 Share Posted January 8, 2010 Ive currently got a code to pull out certain words from a piece of text based on the preceding word <?php $text = 'My name is Jay and I like the color blue'; if(preg_match('%my name is (?P<name>\w+)%i', $text, $out)) { $name = $out['name']; } if(preg_match('%color (?P<color>green|red|orange|yellow|pink|black|white|blue)%i', $text, $out)) { $color = $out['color']; } echo '<pre>'.print_r(get_defined_vars(), true).'</pre>'; if(isset($name) && isset($color)) { echo "Hello $name, $color is a nice color!"; } ?> however i would like to be able to add the text through a textbox rather than have the text written into the code, whenever i try to do this, nothing is displayed. does anyone know how i should be going about it? thanks in advance for any help des Link to comment https://forums.phpfreaks.com/topic/187711-textbox-confusion/ Share on other sites More sharing options...
piyush23424 Posted January 8, 2010 Share Posted January 8, 2010 replace the echo statement with this echo "hello <input type='text' name='txtbox' value='".$name."'> $color is a nice color!"; Link to comment https://forums.phpfreaks.com/topic/187711-textbox-confusion/#findComment-991001 Share on other sites More sharing options...
desmondMorris Posted January 8, 2010 Author Share Posted January 8, 2010 thanks for the reply, i think i phrased the question badly, its the $text = 'My name is Jay and I like the color blue'; that i would like to have inputted by a user in a textbox if that makes sense. des Link to comment https://forums.phpfreaks.com/topic/187711-textbox-confusion/#findComment-991003 Share on other sites More sharing options...
piyush23424 Posted January 8, 2010 Share Posted January 8, 2010 for that you have to make a form <?php if(isset($_POST['submit'])){ $text = $_POST['txt']; if(preg_match('%my name is (?P<name>\w+)%i', $text, $out)) { $name = $out['name']; } if(preg_match('%color (?P<color>green|red|orange|yellow|pink|black|white|blue)%i', $text, $out)) { $color = $out['color']; } //echo '<pre>'.print_r(get_defined_vars(), true).'</pre>'; if(isset($name) && isset($color)) { echo "Hello $name, $color is a nice color!"; } } ?> <form name='testForm' action='' method='post'> <input type='text' name='txt' value=''> <input type='submit' name='submit' value='submit'> </form> Link to comment https://forums.phpfreaks.com/topic/187711-textbox-confusion/#findComment-991030 Share on other sites More sharing options...
desmondMorris Posted January 11, 2010 Author Share Posted January 11, 2010 thanks alot, that was a massive help Link to comment https://forums.phpfreaks.com/topic/187711-textbox-confusion/#findComment-992689 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.