-1
           foreach($posts as $post)
    {
        $words = preg_split("/\|/", $post);
        $author     = trim($words[0]) . ' ' . trim($words[1]);
        $title      = trim($words[2]);
        $comment    = trim($words[3]);
        $priority   = trim($words[4]);
        $filename   = trim($words[5]);
        $postedTime = $words[6];

I'm passing a .txt file into an html form, the file is missing some information that I am not supposed to display. When reading it I get an undefined offset 6 on $postedTime, the file is missing the value. Any ideas how to avoid the message?

2 Answers2

0

To avoid the message You can do something like this:

$postedTime = isset($words[6]) && !empty($words[6]) ? $words[6] : '';
0

try this:

$postedTime = (isset($words[6]))?$words[6]:'';
Praveen P K
  • 198
  • 12
  • Although this code may help to solve the problem, it doesn't explain _why_ and/or _how_ it answers the question. Providing this additional context would significantly improve its long-term value. Please [edit] your answer to add explanation, including what limitations and assumptions apply. – Toby Speight Jun 07 '17 at 19:51