Use of undefined constant error

Joined
Mar 25, 2021
Messages
28
Reaction score
0
Hi, I am getting a use of undefined constant error on items like title, description, pubdate, etc. is the fix to this just to encapsulate everything in ' ' ?

PHP:
} else if ($fileName == 'video') {
        for($i = 0; $i < count($items); $i++) {
            if ($items[$i][description] != '') {
                $feed .= '<item>';
                $feed .= '<title><![CDATA['.$items[$i][title].']]></title>';
                $feed .= '<description><![CDATA['.$items[$i][description].']]></description>';
                $feed .= '<pubDate>'.convertPubDate($items[$i][pubDate], 'l, M. dS, g:iA').'</pubDate>';
                $feed .= '<link><![CDATA['.$items[$i][link].']]></link>';
                if ($items[$i][mediacast.':'.thumbii] != '') {
                    $feed .= '<thumb>'.$items[$i][mediacast.':'.thumbii].'</thumb>';
                } else {
                    $feed .= '<thumb>https://mydomain.com/wp-content/themes/mytheme/assets/images/video.jpg</thumb>';
                }
                $feed .= '</item>';
            }
        }
    }

Does this work?

PHP:
} else if ($fileName == 'video') {
        for($i = 0; $i < count($items); $i++) {
            if ($items[$i][description] != '') {
                $feed .= '<item>';
                $feed .= '<title><![CDATA['.$items[$i]['title'].']]></title>';
                $feed .= '<description><![CDATA['.$items[$i]['description'].']]></description>';
                $feed .= '<pubDate>'.convertPubDate($items[$i]['pubDate'], 'l, M. dS, g:iA').'</pubDate>';
                $feed .= '<link><![CDATA['.$items[$i]['link'].']]></link>';
                if ($items[$i][mediacast.':'.thumbii] != '') {
                    $feed .= '<thumb>'.$items[$i][mediacast.':'.thumbii].'</thumb>';
                } else {
                    $feed .= '<thumb>https://mydomain.com/wp-content/themes/mytheme/assets/images/video.jpg</thumb>';
                }
                $feed .= '</item>';
            }
        }
    }

I use Sublime Text 3, is there some syntax checker I could run my code through for stuff like this to make sure I get it all?
 
Joined
Mar 11, 2022
Messages
227
Reaction score
32
First of all, hust as better coding habit use ['description'] instead of description. Both work, It's just a "way of should do" not "way have to".

Next is simple.

Code:
if ($items[$i][description] != '') {
i would go with something like this: (untested)
Code:
function lenNotNull($array){
    $okay=true;
    foreach($array as $key => $val){
          $v=trim($val);
          if(strlen($v)<1){return false;}
    }
 return $okay;
}

And then just
Code:
 if (lenNotNull($items[$i])) {
instead of
Code:
 if ($items[$i][description] != '') {
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top