Jump to content

[SOLVED] How do I search for a string broken up by new lines


BenPac

Recommended Posts

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

 

 

 

 

 

 

 

 

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']);

}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.