Jump to content

Help to understand this array element


slongmire

Recommended Posts

Hello - I am having trouble getting a weather sticker php script to work properly. I have been working with the guys that wrote it, but so far they haven't come up with a solution. They/we have narrowed it down to the section of the script that compares a text string (which has been converted into UPPER CASE) from a file generated by the weather station, with an array. It is supposed to match an index in the array, that points to which graphic file to generate. This works about 30% of the time. (When the text string is VERY SIMPLE - like CLOUDY or CLEAR or RAIN) But not when the text string is more complex, like HEAVY RAIN, MIST OVERCAST, LIGHT RAIN or PARTLY CLOUDY.

 

Here is the line that defines one of the elements in the array:

 

$vws_icon["PARTLY|MOSTLY+CLOUDY|SUNNY+THUNDERSTORM"] = "./icons/" . "$daynight" . "_tstorm.$image_format";

 

I did not incluse the whole script, nor the whole array because of its length.

 

My Question (Finally...) is --- in the line above within the square braces, he has enclosed a string in double quotes, but the string is delimited by | characters and + characters. Can someone explain to me in English what this means? I have tried reading through two big reference books on php arrays, and they only made me even less certain. (For example: "the line means - If the string is PARTLY or MOSTLY CLOUDY or SUNNY and THUNDERSTORM, then set $vws_icon to whtever the $daynight._tstorm.$image_format evaluates to.) I know, my example translation makes NO SENSE in English. Maybe it makes no sense in php either? I think what he's trying to ask is "If the string contains 'THUNDERSTORM' and any of these other words, then generate the correct icon file for thunderstorm".

 

Any help would be greatly appreciated!

 

Steve

Link to comment
Share on other sites

"PARTLY|MOSTLY+CLOUDY|SUNNY+THUNDERSTORM" = string plain and simple

 

so the array $vws_icon has a key called "PARTLY|MOSTLY+CLOUDY|SUNNY+THUNDERSTORM" (kinda long) with a value of "./icons/" . "$daynight" . "_tstorm.$image_format"

 

$daynight & $image_format will have values that will be pulled inn

Link to comment
Share on other sites

I'm not sure we can answer your question. The + and | in the array index above have no inherent meaning. The person programming it must be parsing that string somewhere. Either that parsing has a bug or does noto account for all the possible combinations.

 

However, I will venture a guess that the string is parsed in such a way that the plus signs indicate elements that may be concatenated together. And the pipe symbols represent ORs. So your above example "could" have the following matches:

 

"PARTLY|MOSTLY+CLOUDY|SUNNY+THUNDERSTORM"

 

- PARTLY CLOUDY THUNDERSTORM

- PARTLY SUNNY THUNDERSTORM

- MOSTLY CLOUDY THUNDERSTORM

- MOSTLY SUNNY THUNDERSTORM

 

If all the parameters are not required, there would be more possibilities. Again, this is just a guess on my part since I can't see where the text is parsed.

Link to comment
Share on other sites

The + and | in the array index above have no inherent meaning.

 

Thank you, mjdamato! THAT statement at least makes me feel a little better, as I was beginning to feel quite "challenged" trying to find out if they had some special logical function within the index.

 

Your interpretation of the potential meaning of this very long string is also helpful. I will look through the long and winding code again tonight with this insight.

 

Steve

 

PS - The guys that wrote it freely admit they are NOT programmers or php programmers, but rather weather hobbiests who are trying to write a script that will work with the output strings from many different weather data consoles. Since there are at least 5 different major manufacturers, each with lots of different models, it is kind of like designing a universal car seat cover that fits perfectly any model! They, and now, I are (am) just trying to figure out why the script is showing clear sunny icons when it's raining cats and dogs!

Link to comment
Share on other sites

PS - The guys that wrote it freely admit they are NOT programmers or php programmers, but rather weather hobbiests who are trying to write a script that will work with the output strings from many different weather data consoles. Since there are at least 5 different major manufacturers, each with lots of different models, it is kind of like designing a universal car seat cover that fits perfectly any model! They, and now, I are (am) just trying to figure out why the script is showing clear sunny icons when it's raining cats and dogs!

 

It shouldn't be too difficult as long as you know the parameters of the data you would receive from each source. Just create a separate "library" for each source instead of trying to create a combined library. Otherwise maintenance will be a real challenge, because one of these services will change their parameters at some time.

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.