Jump to content

Image array


Dada78

Recommended Posts

I have a simple page that displays the current US Threat Advisory as you can see here...

 

http://www.mesquitechristmas.com/weather/hw3.php?forecast=usthreatadvisory

 

At the bottom of the page you will see it says Elevated. Where it says Elevated I want it to show the corresponding image as it shows on that page. Currently it shows a color instead but I have that call removed and just have it show the text. So basically I just want to replace the text with an image. Here is the code that displays the text. How would I go about change it to where it would show the image instead of the text. Now this is not the entire file, just the snippet for the code that outputs the text. I tried a couple of different things but nothing worked.

 

//<THREAT_ADVISORY CONDITION="ELEVATED" />
      		if (preg_match('/<THREAT_ADVISORY\s+?CONDITION\s*?=\s*?"([^"]+)"/', $wx_data,$m)) {
      		$threat_advisory_level = $this->threat_advisory_level= strtoupper($m[1]);
      		if ($threat_advisory_level == 'SEVERE') {
			$this->threat_advisory_color = 'red';
			$this->threat_advisory_color_hex = 'FF0000';
		}
		elseif ($threat_advisory_level == 'HIGH') {
			$this->threat_advisory_color = 'orange';
			$this->threat_advisory_color_hex = 'FFA500';
		}
		elseif ($threat_advisory_level == 'ELEVATED') {
			$this->threat_advisory_color = 'yellow';
			$this->threat_advisory_color_hex = 'FFFF00';
		}
		elseif ($threat_advisory_level == 'GUARDED') {
			$this->threat_advisory_color = 'blue';
			$this->threat_advisory_color_hex = '0000FF';
		}
		elseif ($threat_advisory_level == 'LOW') {
			$this->threat_advisory_color = 'green';
			$this->threat_advisory_color_hex = '00FF00';
		}

 

 

Here is the entire file....

 

<?php
/*
#######################
#  HAMweather 3
#  This script is copyright(c) 2003 by HAMweather, LLC all rights reserved.
#  It is subject to the license agreement that can be found at the following
#  URL: http://www.hamweather.net/hw3/license.shtml
#######################
*
* Revision:
* $Id$
*
*/


require_once("FetchWxData.php");

class FetchUSThreatAdvisory {
var $cfg;
var $debug = false;
var $core_path ='';

var $threat_advisory_level = 'UNKNOWN';
var $threat_advisory_color = 'white';
var $threat_advisory_color_hex = 'FF0000';

Function FetchUSThreatAdvisory($core_path) {
	$this->core_path = $core_path;
}

Function Debug ($mode) {
	$this->debug = $mode;
}


Function usthreatadvisory (&$var, &$form, $forecast, &$cfg, &$forecast_info, $debug) {

	$error = "";

	list($iwin_file, $ma, $t,$lib,$code,$tcode) = $forecast_info;

	$cache_path =$cfg->val('Paths', 'cache');
	if (!$cache_path) { $cache_path =  'cache'; }
	if (!preg_match('/^(?:\/|[A-Za-z]:)/', $cache_path) ) $cache_path = $this->core_path . $cache_path;

	if ($debug) print "alt_zone_info=$alt_zone_info<br>\n";

	$cache_file = preg_replace("/%%(\w+)%%/e", '$$1', $cfg->Val('URLs', 'usthreatadvisory_cache_file'));
	if (!$cache_file) {$cache_file = $cache_path . '/us-threatadvisory.txt'; }

	//Call Fetch Forcast
	$data  = &fetch_forecast($cfg,$ma, $cache_file, '','',
		$cfg->val('URLs', 'usthreatadvisory_url'), $cfg->Val('URLs', 'usthreatadvisory_prefix'),
		$cfg->val('URLs', 'usthreatadvisory_postfix'), $cfg->val('SystemSettings', 'proxy_port'), $debug,0);

	$wx_data = $data[1];

	$this->threat_advisory_level = 'UNKNOWN';
	$this->threat_advisory_color = 'white';
	$this->threat_advisory_color_hex = 'FFFFFF';

	//<THREAT_ADVISORY CONDITION="ELEVATED" />
      		if (preg_match('/<THREAT_ADVISORY\s+?CONDITION\s*?=\s*?"([^"]+)"/', $wx_data,$m)) {
      		$threat_advisory_level = $this->threat_advisory_level= strtoupper($m[1]);
      		if ($threat_advisory_level == 'SEVERE') {
			$this->threat_advisory_color = 'red';
			$this->threat_advisory_color_hex = 'FF0000';
		}
		elseif ($threat_advisory_level == 'HIGH') {
			$this->threat_advisory_color = 'orange';
			$this->threat_advisory_color_hex = 'FFA500';
		}
		elseif ($threat_advisory_level == 'ELEVATED') {
			$this->threat_advisory_color = 'yellow';
			$this->threat_advisory_color_hex = 'FFFF00';
		}
		elseif ($threat_advisory_level == 'GUARDED') {
			$this->threat_advisory_color = 'blue';
			$this->threat_advisory_color_hex = '0000FF';
		}
		elseif ($threat_advisory_level == 'LOW') {
			$this->threat_advisory_color = 'green';
			$this->threat_advisory_color_hex = '00FF00';
		}


      	}


	return $t;

}


Function GetValue($key, $index) {
	$old_error_reporting = error_reporting(0);
	$val = '';

	$val = $this->$key;

	error_reporting($old_error_reporting);

	return $val;
}




















}


?>

 

I am sure this is an easy thing to do but I am stuck. So if anyone could give me a hand that would be great...

 

-Thanks

 

 

Link to comment
Share on other sites

Thanks, but I already have the call done. I have it now where it shows the text. I just need it to show the image instead of the text. The first snippet of code I posted is what I use to show the text. How would I could about changing it to show an image instead of text?

 

-Thanks

Link to comment
Share on other sites

change the echo to a return and swap it for.

<?php
return $t;
to
return "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($threat_advisory_level).".gif\" alt=\"{$threat_advisory_level}\" />";
?>

 

Scott.

Link to comment
Share on other sites

the folder with the images is like this

severe.gif

high.gif

elevated.gif

guarded.gif

low.gif

my script takes the threat level and turns it to lowercase then puts it in a <img> tag outputting that will give the required threat level image.

change this

	      	}


	return $t;

}

to

	      	}


	return "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($threat_advisory_level).".gif\" alt=\"{$threat_advisory_level}\" />";

}

 

Scott.

Link to comment
Share on other sites

here i reworte the function i think htis should work. i havn't tested it. i just clicked the link an noticed by nothing u mean a blank page what is the error reporting level i would recomend adding this to display all errors

error_reporting(E_ALL);

here is the rewriten function

<?php
Function usthreatadvisory (&$var, &$form, $forecast, &$cfg, &$forecast_info, $debug) {
	$error = "";
	list($iwin_file, $ma, $t,$lib,$code,$tcode) = $forecast_info;
	$cache_path =$cfg->val('Paths', 'cache');
	if (!$cache_path) { $cache_path =  'cache'; }

	if (!preg_match('/^(?:\/|[A-Za-z]:)/', $cache_path) ) $cache_path = $this->core_path . $cache_path;

	if ($debug) print "alt_zone_info=$alt_zone_info<br>\n";

	$cache_file = preg_replace("/%%(\w+)%%/e", '$$1', $cfg->Val('URLs', 'usthreatadvisory_cache_file'));

	if (!$cache_file) {$cache_file = $cache_path . '/us-threatadvisory.txt'; }

	//Call Fetch Forcast
	$data  = &fetch_forecast($cfg,$ma, $cache_file, '','',
		$cfg->val('URLs', 'usthreatadvisory_url'), $cfg->Val('URLs', 'usthreatadvisory_prefix'),
		$cfg->val('URLs', 'usthreatadvisory_postfix'), $cfg->val('SystemSettings', 'proxy_port'), $debug,0);

	$wx_data = $data[1];

	$this->threat_advisory_level = 'UNKNOWN';
	$this->threat_advisory_color = 'white';
	$this->threat_advisory_color_hex = 'FFFFFF';

	//<THREAT_ADVISORY CONDITION="ELEVATED" />
      		if (preg_match('/<THREAT_ADVISORY\s+?CONDITION\s*?=\s*?"([^"]+)"/', $wx_data,$m)) {
      		$this->$threat_advisory_level = $this->threat_advisory_level= strtoupper($m[1]);
      		$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($this->$threat_advisory_level).".gif\" alt=\"{$this->$threat_advisory_level}\" />";
      	}else{
      		$t = "Threat Level unknown";

	return $t;
}
?>

 

Scott.

Link to comment
Share on other sites

I get this when I use to code above so I have gone back to the old one....

 

Parse error: syntax error, unexpected $end in /home/mesquit1/public_html/weather/hamlib/HW3Plugins/FetchUSThreatAdvisory.php on line 36

 

What I am confused about is where in the code or how does it know what image to assign to which threat level? Does that make sense?

 

For example, elevated use elevated.gif, High use high.gif etc....

 

Because in the way I had it set up for example this one.

 

elseif ($threat_advisory_level == 'HIGH') {
			$this->threat_advisory_color = 'orange';
			$this->threat_advisory_color_hex = 'FFA500';

 

If you notice if the data received from the data source is HIGH it display a orange box with a certain color text. I got all that working and it works great. I have removed those calls in the HTML file though because I wanted to show the new images instead. You see what I mean though, I have assigned colors for assigned threats that show. Don't I need to do that with the images instead somehow so it knows what image to show for each threat level?

 

-Thanks

 

 

Link to comment
Share on other sites

sorry i see the problem with my code i forgot to close a else statement

	      	}else{
      		$t = "Threat Level unknown";

	return $t;
}

needs to be

	      	}else{
      		$t = "Threat Level unknown";
      	}
	return $t;
}

how knows which image it dosn't need to know the color because the color is already in the image and so when $threat_advisory_level = "HIGH" if you convert that to lower case then add .gif you have the name of the image this way we do not need to know what color the image is try the code with the fix it should work.

 

Scott.

Link to comment
Share on other sites

Ah I get what you are saying now, that makes sense. I had to had the function class because it was left off. I am not getting this error which is the last line but I don't see what it is talking about.

 

Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /home/mesquit1/public_html/weather/hamlib/HW3Plugins/FetchUSThreatAdvisory.php on line 69

 

<?php
/*
#######################
#  HAMweather 3
#  This script is copyright(c) 2003 by HAMweather, LLC all rights reserved.
#  It is subject to the license agreement that can be found at the following
#  URL: http://www.hamweather.net/hw3/license.shtml
#######################
*
* Revision:
* $Id$
*
*/


require_once("FetchWxData.php");

class FetchUSThreatAdvisory {
var $cfg;
var $debug = false;
var $core_path ='';

var $threat_advisory_level = 'UNKNOWN';
var $threat_advisory_color = 'white';
var $threat_advisory_color_hex = 'FF0000';

Function FetchUSThreatAdvisory($core_path) {
	$this->core_path = $core_path;
}

Function Debug ($mode) {
	$this->debug = $mode;
}

Function usthreatadvisory (&$var, &$form, $forecast, &$cfg, &$forecast_info, $debug) {
	$error = "";
	list($iwin_file, $ma, $t,$lib,$code,$tcode) = $forecast_info;
	$cache_path =$cfg->val('Paths', 'cache');
	if (!$cache_path) { $cache_path =  'cache'; }

	if (!preg_match('/^(?:\/|[A-Za-z]:)/', $cache_path) ) $cache_path = $this->core_path . $cache_path;

	if ($debug) print "alt_zone_info=$alt_zone_info<br>\n";

	$cache_file = preg_replace("/%%(\w+)%%/e", '$$1', $cfg->Val('URLs', 'usthreatadvisory_cache_file'));

	if (!$cache_file) {$cache_file = $cache_path . '/us-threatadvisory.txt'; }

	//Call Fetch Forcast
	$data  = &fetch_forecast($cfg,$ma, $cache_file, '','',
		$cfg->val('URLs', 'usthreatadvisory_url'), $cfg->Val('URLs', 'usthreatadvisory_prefix'),
		$cfg->val('URLs', 'usthreatadvisory_postfix'), $cfg->val('SystemSettings', 'proxy_port'), $debug,0);

	$wx_data = $data[1];

	$this->threat_advisory_level = 'UNKNOWN';
	$this->threat_advisory_color = 'white';
	$this->threat_advisory_color_hex = 'FFFFFF';

	//<THREAT_ADVISORY CONDITION="ELEVATED" />
      		if (preg_match('/<THREAT_ADVISORY\s+?CONDITION\s*?=\s*?"([^"]+)"/', $wx_data,$m)) {
      		$this->$threat_advisory_level = $this->threat_advisory_level= strtoupper($m[1]);
      		$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($this->$threat_advisory_level).".gif\" alt=\"{$this->$threat_advisory_level}\" />";
      	}else{
      		$t = "Threat Level unknown";
                     }
	return $t;
}
?>

Link to comment
Share on other sites

Ok I closed that but now I am getting this error.

 

Fatal error: Cannot access empty property in /home/mesquit1/public_html/weather/hamlib/HW3Plugins/FetchUSThreatAdvisory.php on line 63

 

Line 63 is this...

 

$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($this->$threat_advisory_level).".gif\" alt=\"{$this->$threat_advisory_level}\" />";

 

Here is the full code...

 

 

<?php
/*
#######################
#  HAMweather 3
#  This script is copyright(c) 2003 by HAMweather, LLC all rights reserved.
#  It is subject to the license agreement that can be found at the following
#  URL: http://www.hamweather.net/hw3/license.shtml
#######################
*
* Revision:
* $Id$
*
*/


require_once("FetchWxData.php");

class FetchUSThreatAdvisory {
var $cfg;
var $debug = false;
var $core_path ='';

var $threat_advisory_level = 'UNKNOWN';
var $threat_advisory_color = 'white';
var $threat_advisory_color_hex = 'FF0000';

Function FetchUSThreatAdvisory($core_path) {
	$this->core_path = $core_path;
}

Function Debug ($mode) {
	$this->debug = $mode;
}

Function usthreatadvisory (&$var, &$form, $forecast, &$cfg, &$forecast_info, $debug) {
	$error = "";
	list($iwin_file, $ma, $t,$lib,$code,$tcode) = $forecast_info;
	$cache_path =$cfg->val('Paths', 'cache');
	if (!$cache_path) { $cache_path =  'cache'; }

	if (!preg_match('/^(?:\/|[A-Za-z]:)/', $cache_path) ) $cache_path = $this->core_path . $cache_path;

	if ($debug) print "alt_zone_info=$alt_zone_info<br>\n";

	$cache_file = preg_replace("/%%(\w+)%%/e", '$$1', $cfg->Val('URLs', 'usthreatadvisory_cache_file'));

	if (!$cache_file) {$cache_file = $cache_path . '/us-threatadvisory.txt'; }

	//Call Fetch Forcast
	$data  = &fetch_forecast($cfg,$ma, $cache_file, '','',
		$cfg->val('URLs', 'usthreatadvisory_url'), $cfg->Val('URLs', 'usthreatadvisory_prefix'),
		$cfg->val('URLs', 'usthreatadvisory_postfix'), $cfg->val('SystemSettings', 'proxy_port'), $debug,0);

	$wx_data = $data[1];

	$this->threat_advisory_level = 'UNKNOWN';
	$this->threat_advisory_color = 'white';
	$this->threat_advisory_color_hex = 'FFFFFF';

	//<THREAT_ADVISORY CONDITION="ELEVATED" />
      		if (preg_match('/<THREAT_ADVISORY\s+?CONDITION\s*?=\s*?"([^"]+)"/', $wx_data,$m)) {
      		$this->$threat_advisory_level = $this->threat_advisory_level= strtoupper($m[1]);
      		$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($this->$threat_advisory_level).".gif\" alt=\"{$this->$threat_advisory_level}\" />";
      	}else{
      		$t = "Threat Level unknown";
                     }
	return $t;
}
    	}
?>

 

Link to comment
Share on other sites

im not sure of the error but replace this

<?php
      		$this->threat_advisory_level = strtoupper($m[1]);
      		$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($this->$threat_advisory_level).".gif\" alt=\"" . $this->$threat_advisory_level . "\" />";
?>

 

Scott.

Link to comment
Share on other sites

try to replace

      		if (preg_match('/<THREAT_ADVISORY\s+?CONDITION\s*?=\s*?"([^"]+)"/', $wx_data,$m)) {
      		$this->$threat_advisory_level = $this->threat_advisory_level= strtoupper($m[1]);
      		$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($this->$threat_advisory_level).".gif\" alt=\"{$this->$threat_advisory_level}\" />";
      	}else{
      		$t = "Threat Level unknown";
                     }
	return $t;
}
    	}
?>

with

      		if (preg_match('/<THREAT_ADVISORY\s+?CONDITION\s*?=\s*?"([^"]+)"/', $wx_data,$m)) {
      		$this->threat_advisory_level = strtoupper($m[1]);
      		$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($this->$threat_advisory_level).".gif\" alt=\"" . $this->$threat_advisory_level . "\" />";
      	}else{
      		$t = "Threat Level unknown";
                     }
	return $t;
}
    	}
?>

 

Scott.

Link to comment
Share on other sites

Still getting the same error except now on line 64. Is their another way to do this without completely rewriting the logic? This was a plugin for the weather software I am using so I am thinking this is not following the logic of the software.

Link to comment
Share on other sites

sorry noob error

i was using $this->$threat_advisory_level when it should have been $this->threat_advisory_level

replace this:

$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($this->threat_advisory_level).".gif\" alt=\"" . $this->threat_advisory_level . "\" />";

and check this

$this->threat_advisory_level = strtoupper($m[1]);

the line before

 

Scott.

Link to comment
Share on other sites

I am getting nothing but a blank page...

 

Here is the full code now with the changes

 

<?php
/*
#######################
#  HAMweather 3
#  This script is copyright(c) 2003 by HAMweather, LLC all rights reserved.
#  It is subject to the license agreement that can be found at the following
#  URL: http://www.hamweather.net/hw3/license.shtml
#######################
*
* Revision:
* $Id$
*
*/


require_once("FetchWxData.php");

class FetchUSThreatAdvisory {
var $cfg;
var $debug = false;
var $core_path ='';

var $threat_advisory_level = 'UNKNOWN';
var $threat_advisory_color = 'white';
var $threat_advisory_color_hex = 'FF0000';

Function FetchUSThreatAdvisory($core_path) {
	$this->core_path = $core_path;
}

Function Debug ($mode) {
	$this->debug = $mode;
}


Function USthreatAdvisory (&$var, &$form, $forecast, &$cfg, &$forecast_info, $debug) {
	$error = "";
	list($iwin_file, $ma, $t,$lib,$code,$tcode) = $forecast_info;
	$cache_path =$cfg->val('Paths', 'cache');
	if (!$cache_path) { $cache_path =  'cache'; }

	if (!preg_match('/^(?:\/|[A-Za-z]:)/', $cache_path) ) $cache_path = $this->core_path . $cache_path;

	if ($debug) print "alt_zone_info=$alt_zone_info<br>\n";

	$cache_file = preg_replace("/%%(\w+)%%/e", '$$1', $cfg->Val('URLs', 'usthreatadvisory_cache_file'));

	if (!$cache_file) {$cache_file = $cache_path . '/us-threatadvisory.txt'; }

	//Call Fetch Forcast
	$data  = &fetch_forecast($cfg,$ma, $cache_file, '','',
		$cfg->val('URLs', 'usthreatadvisory_url'), $cfg->Val('URLs', 'usthreatadvisory_prefix'),
		$cfg->val('URLs', 'usthreatadvisory_postfix'), $cfg->val('SystemSettings', 'proxy_port'), $debug,0);

	$wx_data = $data[1];

	$this->threat_advisory_level = 'UNKNOWN';
	$this->threat_advisory_color = 'white';
	$this->threat_advisory_color_hex = 'FFFFFF';

	//<THREAT_ADVISORY CONDITION="ELEVATED" />
      		if (preg_match('/<THREAT_ADVISORY\s+?CONDITION\s*?=\s*?"([^"]+)"/', $wx_data,$m)) {
      		$this->threat_advisory_level = strtoupper($m[1]);
      		$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/".strtolower($this->threat_advisory_level).".gif\" alt=\"" . $this->threat_advisory_level . "\" />";
      	}else{
      		$t = "Threat Level unknown";
                     }
	return $t;
}
    	}
?>

Link to comment
Share on other sites

i copied the whole class had a real close look at it. i can't see any problems i added a new debug output run this and post the output

<?php
/*
#######################
#  HAMweather 3
#  This script is copyright(c) 2003 by HAMweather, LLC all rights reserved.
#  It is subject to the license agreement that can be found at the following
#  URL: http://www.hamweather.net/hw3/license.shtml
#######################
*
* Revision:
* $Id$
*
*/


require_once ("FetchWxData.php");

class FetchUSThreatAdvisory {
var $cfg;
var $debug = false;
var $core_path = '';

var $threat_advisory_level = 'UNKNOWN';
var $threat_advisory_color = 'white';
var $threat_advisory_color_hex = 'FF0000';

function FetchUSThreatAdvisory($core_path) {
	$this->core_path = $core_path;
}

function Debug($mode) {
	$this->debug = $mode;
}


function USthreatAdvisory(&$var, &$form, $forecast, &$cfg, &$forecast_info, $debug) {
	$error = "";
	list($iwin_file, $ma, $t, $lib, $code, $tcode) = $forecast_info;
	$cache_path = $cfg->val('Paths', 'cache');
	if (!$cache_path) {
		$cache_path = 'cache';
	}

	if (!preg_match('/^(?:\/|[A-Za-z]:)/', $cache_path))
		$cache_path = $this->core_path . $cache_path;

	if ($debug)
		print "alt_zone_info=$alt_zone_info<br>\n";

	$cache_file = preg_replace("/%%(\w+)%%/e", '$$1', $cfg->Val('URLs', 'usthreatadvisory_cache_file'));

	if (!$cache_file) {
		$cache_file = $cache_path . '/us-threatadvisory.txt';
	}

	//Call Fetch Forcast
	$data = &fetch_forecast($cfg, $ma, $cache_file, '', '', $cfg->val('URLs', 'usthreatadvisory_url'), $cfg->Val('URLs', 'usthreatadvisory_prefix'), $cfg->val('URLs', 'usthreatadvisory_postfix'), $cfg->val
		('SystemSettings', 'proxy_port'), $debug, 0);

	$wx_data = $data[1];

	$this->threat_advisory_level = 'UNKNOWN';
	$this->threat_advisory_color = 'white';
	$this->threat_advisory_color_hex = 'FFFFFF';

	//<THREAT_ADVISORY CONDITION="ELEVATED" />
	if (preg_match('/<THREAT_ADVISORY\s+?CONDITION\s*?=\s*?"([^"]+)"/', $wx_data, $m)) {
		$this->threat_advisory_level = strtoupper($m[1]);
		if ($debug)
			var_dump($this->threat_advisory_level);
		$t = "<img src=\"http://www.mesquitechristmas.com/weather/images/" . strtolower($this->threat_advisory_level) . ".gif\" alt=\"" . $this->threat_advisory_level . "\" />";
	} else {
		$t = "Threat Level unknown";
	}
	return $t;
}
}
?>

 

Scott.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.