ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP error within EE 2.5.3 - likely related to conditionals in PHP script?

November 18, 2012 5:46pm

Subscribe [1]
  • #1 / Nov 18, 2012 5:46pm

    HawaiiMotion

    1 posts

    Hi guys, I’ve been trying to find out what’s causing this problem, but all my searches are taking me in circles so I thought I’d just post and ask straight up. I think it’s a conflict between my PHP script and EE somewhere, but since I’m a total PHP newbie, I’m a bit in over my head as to figuring this one out.

    Here’s the jist… I have a feed I’m importing that looks something like this:

    2012-11-08;;1;;0,2012-11-09;;1;;0,2012-11-10;;1;;0,2012-11-13;;2;;0,etc, etc

    Nothing too complex, pretty basic. Using PHP I’m trying to break the feed down to where I can grab just the string items that have a “2” in them after the date. But my PHP script is throwing this errors back out:

    A PHP Error was encountered
    Severity: Notice
    Message: Undefined offset: 2
    Filename: libraries/Functions.php(680) : eval()‘d code
    Line Number: 14

    Here’s my script below… something’s not right with it I’m sure, but like I said, I’m still learning the basics here. I really could use some help in getting this working within EE. FWIW I know it’s the if($date[2] == 2) line that’s causing the problem. I wrote another script for this task that was giving me a similar errors, so I’m sure it’s something to do with the conditionals in EE.

    <?php
    $myFile = file_get_contents('http://url_to_my_file_here/');
    
        $element = explode(",", $myFile);
        $array = array();
        foreach($element as $row){
            array_push($array, explode(";", $row));
        }
        
        foreach($array as $date){
            $newdate = new DateTime($date[0]);
            $newdate = $newdate->format('m-d-Y');
            //echo $newdate;
            if($date[2] == 2)
               echo '"'.$newdate.'",';
            }
    ?>

    Any tips or ideas would be most appreciated.

    Thanks,

    - John

  • #2 / Nov 20, 2012 2:57pm

    Dan Decker

    7338 posts

    Hi John,

    Welcome to the Forums!

    The error is complaining that your $date[2] variable is empty. We need to see the contents of the $data array, so let’s get a look at that:

    ...
    
    foreach($array as $date){
            echo '<pre>';
            var_dump($date);
            echo '</pre><p>‘;<br />
            }<br />
    ?>
    </pre>

    let me know the result!

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases