Jump to content

Textarea, reading line by line (Simple I know)


papaface

Recommended Posts

Hello,

How can I read a textareas contents line by line?

e.g

A link on each line that needs to be parsed separately.

 

Is this the right way to do it?

<?php

if	($_POST['submit'])
{
$text = explode("<br />",nl2br($_POST['links']));
foreach ($text as $key => $value)
	{
        echo $key . " => " . $value."<br />";
	}
}
else
{?>
<form name="links" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name="links" rows="20" cols="50"></textarea>   <br />
<input type="submit" name="submit" value="Send">
</form>
<?php
}
?>

<?php

if	($_POST['submit'])
{
$text = explode("\n",$_POST['links']);
foreach ($text as $key => $value)
	{
        echo $key . " => " . $value."<br />";
	}
}
else
{?>
<form name="links" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name="links" rows="20" cols="50"></textarea>   <br />
<input type="submit" name="submit" value="Send">
</form>
<?php
}
?>

So thats the way to do it?

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.