Jump to content

Image From Keywords


standers

Recommended Posts

I need to display a graphic whenever certain keywords are displayed on this page http://www.weather.gov/data/MTR/AFDMTRIs something like this possible with JavaScript?many thanks.
I would like to display a red light icon .gif on a webpage whenever the words THUNDERSTORMS and or RAMP UP are used on this page http://www.weather.gov/data/MTR/AFDMTR and a different .gif image when other words are used.
Link to comment
Share on other sites

Then yeah, you can use Javascript for that. Unfortunately, in order to get the file at all, you'll need to use both Javascript and PHP (or ASP, or ColdFusion, Perl, etc). Javascript can only access files on the same domain, so if you want a file on another domain you'll need to have Javascript send a request to a PHP page on your domain, which can get the actual file and return it to Javascript (PHP is able to contact remote domains, assuming the PHP settings on your server allow it).But, if you have PHP access on your server, you could also use PHP only and not have to use Javascript. It would still be quicker for the user if you used Javascript, but it's not necessary.On the PHP side, you can use file_get_contents to load the content of that file, assuming the PHP settings on the server allow PHP to do that:http://www.php.net/manual/en/function.file-get-contents.phpOne way would be to have PHP check for the keywords and just tell Javascript which image to display. To do that, you can use strpos to check for the existence of a keyword in your string:http://www.php.net/manual/en/function.strpos.phpThen you can decide which image to show. If you want to have PHP send the entire thing to Javascript and use Javascript to search, then you would use the string.indexOf method to search for a keyword:http://www.w3schools.com/jsref/jsref_indexof.aspIf you want to use the Javascript method, you'll also need to read through the ajax tutorial to see how to send the request to the PHP proxy and get the response back.

Link to comment
Share on other sites

Thank you for the fast response and the help. I really needed it. You are not justsomeguy you are THE MAN! I'll save myself the time and go the PHP route.

Then yeah, you can use Javascript for that. Unfortunately, in order to get the file at all, you'll need to use both Javascript and PHP (or ASP, or ColdFusion, Perl, etc). Javascript can only access files on the same domain, so if you want a file on another domain you'll need to have Javascript send a request to a PHP page on your domain, which can get the actual file and return it to Javascript (PHP is able to contact remote domains, assuming the PHP settings on your server allow it).But, if you have PHP access on your server, you could also use PHP only and not have to use Javascript. It would still be quicker for the user if you used Javascript, but it's not necessary.On the PHP side, you can use file_get_contents to load the content of that file, assuming the PHP settings on the server allow PHP to do that:http://www.php.net/manual/en/function.file-get-contents.phpOne way would be to have PHP check for the keywords and just tell Javascript which image to display. To do that, you can use strpos to check for the existence of a keyword in your string:http://www.php.net/manual/en/function.strpos.phpThen you can decide which image to show. If you want to have PHP send the entire thing to Javascript and use Javascript to search, then you would use the string.indexOf method to search for a keyword:http://www.w3schools.com/jsref/jsref_indexof.aspIf you want to use the Javascript method, you'll also need to read through the ajax tutorial to see how to send the request to the PHP proxy and get the response back.
Link to comment
Share on other sites

  • 1 month later...

No. The search() method takes regular expressions, however.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...