In a textarea, I'm pasting random datas following one pattern:
Data1 Data2 Data3 Data4 Data5 Data6 Data7
Data8 Data9 Data10 Data11 Data12 Data13 Data14
Like:
name [4*SPACE] surname [4*SPACE] address [4*SPACE] country [4*SPACE] phone [4*SPACE] sex [4*SPACE] age [4*SPACE] [line break]
And in this pattern, the last data (age here) can be empty.
So I did:
<form>
<textarea rows="15" cols="100" name="query" id="pastedata">Paste datas there.</textarea>
<p style="margin-left: 320px;"><input type="submit" name="submit"value="Submit" /></p>
</form>
<?php
if(isset($_GET['query'])) {
$query = $_GET['query'];
$query = str_replace(' ', ',', $query);
$query = str_replace("\n", ',', $query);
$info = explode (',', $query);
$result = array_map('trim', $info);
print_r(array_chunk($result, 7));
}
It does its job... PHP returns a multidimensionnal array following the pattern of 7 columns, except if the last data is empty so it will shift the next array's first row.
How can I say to PHP that if in any array the last value is empty then just return something like 'Empty data' ?
This is my first PHP lines so I'm sure the structure is broken.
EDIT: Thanks a lot everyone, it now works as expected !
$query = trim($_GET['query'])