This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

alec18859
alec18859

Hi im loving this CMS but im having some trouble migrating some php code over from a wordpress site. I understand partials and calling them into the pages but i cant work out how to format the php in the code tab ive tried the basics and got it working

{% for column in 0..columns %}

{{ column }}

{% endfor %}

and

function onStart() { $this["columns"] = 19; // perhaps this is the number you get from the database }

But how would i adapt this for my php code

<?php error_reporting(1); @ini_set('implicit_flush', 1); @ini_set('max_execution_time', 2000); @set_time_limit(2000);

date_default_timezone_set('Europe/London'); //$api_urls = "http://polar.ncep.noaa.gov/waves/WEB/multi_1.latest_run/plots/multi_1.62107.bull" ; //$api_urls = "ftp://polar.ncep.noaa.gov/pub/waves/develop/multi_2.latest_run/multi_2.62107.bull" ; $api_urls = "ftp://polar.ncep.noaa.gov/waves/ops/multi_1.latest_run/multi_1.62107.bull" ;

$text = getSslPage($api_urls);
$rows = explode("\n",$text);

$data = array();
for($i = 7;$i<197;$i++)
{
    $row = $rows[$i];
    $cols = explode("|",$row);

    $desired_col = array();
    if(trim($cols[3])!="")$desired_col[0] = explode(" ",trim(str_replace(array("*","  "),array(""," "),$cols[3])));
    if(trim($cols[4])!="")$desired_col[1] = explode(" ",trim(str_replace(array("*","  "),array(""," "),$cols[4])));
    if(trim($cols[5])!="")$desired_col[2] = explode(" ",trim(str_replace(array("*","  "),array(""," "),$cols[5])));
    if(trim($cols[6])!="")$desired_col[3] = explode(" ",trim(str_replace(array("*","  "),array(""," "),$cols[6])));
    if(trim($cols[7])!="")$desired_col[4] = explode(" ",trim(str_replace(array("*","  "),array(""," "),$cols[7])));
    if(trim($cols[8])!="")$desired_col[5] = explode(" ",trim(str_replace(array("*","  "),array(""," "),$cols[8])));

    $sw_height = explode(" ",trim(str_replace(array("*","  "),array(""," "),$cols[2])));

    $desired_data[0] = $sw_height[0];
    $desired_data[1] = avg($desired_col,1);
    $desired_data[2] = avg($desired_col,2);
    $desired_data[3] = str_replace(array("  "," "),array(" ",":"),trim($cols[1]));
    $pieces = explode(":", $desired_data[3]);
    $month = date('m-Y');
    $desired_data[4] = strtotime($pieces[0].'-'.$month.' '.$pieces[1].':00');

    if($desired_col)
    {
        $data[] = $desired_data; 
    }
}

function avg($array = array(),$index = 1)
{
    $count = 0;
    $sum = 0;
    foreach($array as $ar)
    {
        $sum += $ar[$index];
        $count++;
    }
    return $sum/$count;
}

function getSslPage($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;

}   

?>

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.