BenPac Posted May 5, 2007 Share Posted May 5, 2007 Just started to learn php and would be grateful for some help. My problem is that I want to search a string coming from a textarea, but the substring I want to identify is broken up by newlines and is not returned. How do I solve this. For example: Input in the textarea: MyNameIsJohnMc LoudAndIam3040 How do I identify Mcloud or basically producing the string: MyNameIsJohnMcLoudAndIam3040 Quote Link to comment https://forums.phpfreaks.com/topic/50116-solved-how-do-i-search-for-a-string-broken-up-by-new-lines/ Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 try this <form method="post" action=""> <textarea name="textarea">MyNameIsJohnMc LoudAndIam3040</textarea> <input name="submit" type="submit" value="submit" /> </form> <?php if( isset($_POST['submit']) ) { //Leaves a space //echo preg_replace('#\n#sim', '', $_POST['textarea']); //clears the space echo preg_replace('#\s?\n\s?#sim', '', $_POST['textarea']); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50116-solved-how-do-i-search-for-a-string-broken-up-by-new-lines/#findComment-246070 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.