<textarea>
Apple | 1000 | $5
Banana | 500 | $5
Coconut | 1500 | $5
</textarea>
How To
1) Binding each string before the spesific symbol ?
The result must be
Fruits : Apple, Banana, Coconut
Quantity : 1000, 500, 1500
Prices : $5, $5, $5
I have tried this one Get each line from textarea to split each line and it's work, but i don't know how to bind it
UPDATE
I've tried to build it by myself and it's work fine
<html>
<form method="post">
<textarea name="market"></textarea>
<button type="submit">Split</button>
</form>
</html>
<?php
if(isset($_POST['market'])) {
$text = trim($_POST['market']);
$text = str_replace(' ', '', $text);
$textAr = explode("\n", $text);
$textAr = array_filter($textAr, 'trim');
foreach ($textAr as $line) {
$var = explode('|', $line);
$fruit = $var[0];
$quantity = $var[1];
$price = $var[2];
$data['fruits'][] = $fruit;
}
echo 'Fruits : '; foreach($data['fruits'] as $rows) { echo $rows.', '; }
}
?>
Now i want to ask, how to prevent it from error ?
for example users only input it with
<textarea>
Apple | 1000
Banana | 500 \ $5
Coconut | 1500 / $5
</textarea>
Always got error from all of above