P
P
Petro Boyko2018-02-27 22:08:28
PHP
Petro Boyko, 2018-02-27 22:08:28

How to exclude empty string from output?

Tell me how to exclude an empty line with random output, that is, there is a csv file
in the file there is an entry of type
1; fork
2; plate
3; spoon
and the fourth line are empty, the line break
has already twisted and this way and that all the same skips the empty line
here is the code itself

$out = " ";
$list = explode("\n",$data);
$arr = array_map('trim', $list);
shuffle($arr);
srand ((float) microtime() * 10000000);
for($i=0; $i<1; $i++) 
{
  if(!strripos($arr[$i], "<|>")) continue;
  if (!isset($arr[$i])) break;
    $elem = explode('<|>',$arr[$i]);
 
  $out .= ("<a style=color:".$elem[1]."; href=".$elem[2]." target='_blank' title=".$elem[3]."><b>".$elem[4]."</b> ".$elem[5]."</a>");
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2018-02-27
@VladimirAndreev

trim($data)

O
Oleg, 2018-02-28
@402d

In a leaf loop, add only non-empty values ​​to the array app.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question