472,145 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

explode() Function

<?php
$numbers=$_POST['numbers'];

if(!$_POST['Submit']) { ?>
<form name="form1" method="post" action="">
<p>
<textarea name="numbers" cols="100" rows="15"
id="numbers"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<?
} else {
//$replaced=preg_replace("/\n$/", ',', $numbers);
$exploded=explode('\n', $numbers);
?>
<form name="form1" method="post" action="">
<p>
<textarea name="numbers" cols="100" rows="15" id="numbers"><? echo
$exploded[0], $exploded[1]; ?></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<? } ?>

----------------------------------------------

I have this code, I need to insert some numbers in the textbox

for example:

585284
582084
585209
964587

and so on, then i want them to be exploded and echoed back separated by
commas. How can i exploded then into an array separated by new line?

Jul 17 '05 #1
4 3385
Maximus пишет:
<?php skipped ----------------------------------------------

I have this code, I need to insert some numbers in the textbox

for example:

585284
582084
585209
964587

and so on, then i want them to be exploded and echoed back separated by
commas. How can i exploded then into an array separated by new line?


split ?
Split string into array by regular expression (PHP 3, PHP 4 , PHP 5)
array split ( string pattern, string string [, int limit] )
Jul 17 '05 #2
i need the key code for ENTER.
i can explode but i need to know what to put as a delimeter.

what is the enter key in the delimeter.

Jul 17 '05 #3
Maximus wrote:
<?php
$numbers=$_POST['numbers'];

if(!$_POST['Submit']) { ?>
<form name="form1" method="post" action="">
<p>
<textarea name="numbers" cols="100" rows="15"
id="numbers"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<?
} else {
//$replaced=preg_replace("/\n$/", ',', $numbers);
$exploded=explode('\n', $numbers);
?>
<form name="form1" method="post" action="">
<p>
<textarea name="numbers" cols="100" rows="15" id="numbers"><? echo
$exploded[0], $exploded[1]; ?></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<? } ?>

----------------------------------------------

I have this code, I need to insert some numbers in the textbox

for example:

585284
582084
585209
964587

and so on, then i want them to be exploded and echoed back separated by
commas. How can i exploded then into an array separated by new line?


Your code seems overly complicated. Try:

<form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']
?>">
<p>
<textarea name="numbers" cols="100" rows="15" id="numbers">
<? if(isset($_POST['Submit']))
echo implode(', ',explode("\n",$_POST['numbers'])); ?></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

Ken

Jul 17 '05 #4
Maximus пишет:
i need the key code for ENTER.
i can explode but i need to know what to put as a delimeter.

what is the enter key in the delimeter.

Under Windows it's \r\n
Under Unix OS it's only \n
Just trim($textarea, "\r") then split using \n
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by the friendly display name | last post: by
12 posts views Thread by frizzle | last post: by
5 posts views Thread by FFMG | last post: by
5 posts views Thread by DJH | last post: by
3 posts views Thread by lbvox | last post: by
5 posts views Thread by sathyashrayan | last post: by
8 posts views Thread by vinpkl | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.