469,282 Members | 2,034 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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 3319
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 zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.