How to replace custom commands in my weather php5 script?

I am trying to move my files from godaddy to infinityfree. I have ten years cpanel and php experience.

I’ve built a weather page with current weather data, moon phase, seven day forecast, regional and local radar. I would like php solutions but all suggestions are welcomed.

How to replace custom commands in my weather php5 script?
I am working on http://dfellows.rf.gd/site_html/weather13.php

Part of weather13.php:

$filename = 'ksgf.xml';
$searchString = 'wind_string';
if(file_exists($filename)){//if $filename exists check it for searchString.
if(exec('grep '.escapeshellarg($searchString).' '.$filename)) {
if(strlen($weather->wind_string)<=5){echo $weather->wind_string; goto end;}
if(!preg_match('/^[f]/i',$weather->wind_string)){list($a,$b)=explode('(',$weather->wind_string);echo $a;goto end;}
if(preg_match('/^[f]/i',$weather->wind_string)){list($a,$b)=explode('(',$weather->wind_string);echo substr($a,8,44);goto end;}
}    else     {echo "No wind data at this time";}} 

I should be seeing this:
image

Instead I get my custom error message “No wind data at this time”

To bust caching I add the results of:

/* CACHE BUSTING HASHSTAMP IN GRAPHICS FILENAMES */
$hash2=hash_file('crc32', '../images/weather-seven-day-forecast-graphic.jpg');

to the filenames of the moonphase and seven day forecast graphics. Can I do this on free hosting? If not how can I accomplish this using php?

I’ve enabled display errors with alter php config.

You can’t run custom commands on free hosting, and that’s why the exec function is disabled.

1 Like

How can I accomplish this w/o using custom commands on free hosting?

You’re looking for the line in the file which contains the text wind_string? That should be quite easy to do in PHP too.

A few approaches you can take (depending on personal preference and the size of the file):

  • Read the entire file into memory with file_get_contents and check the presence and location of the string with strpos.
  • Read the file into memory in separate lines with the file function and iterate of the lines.
  • Open a file pointer with fopen and read it line by line with fgets (harder to do but doesn’t require the entire file to be loaded into memory, so good for big files).
2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.