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
}
?>

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.