Jump to content

funsutton

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

funsutton's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey, here is a separate string, similar to the other, however it has no F or C to denote the actual temperatures. How hard would it be to modify your preg_replace to only change the ones that are temps...and not the ones that are actual dates and times? mpdData['HMhour'].hour['0']=new mpdHMHrObj(new Date('2008','7','31','0','0','0'),'11','Few Showers','74','74','30','69','87','From S 2 mph'); The trick is, in this section "'Few Showers','74','74','30','69','87','From S 2 mph'", only the 74,74,69 are temps, and the others are percents.
  2. I actually didn't see the difference, so I switched it out. Thanks man.
  3. Yeah, it does work. I didn't realize that 86 was 30.....so, but cool. Then I actually accomplished something myself. Well, with the code you gave me.
  4. I might be wrong....it might actually be working, and my testing be wrong.
  5. Actually, I do think this works....but it's converting all of the numbers. I want it to only convert the one's with an s, not an F or C. $string = preg_replace('/\b(\d+)(s){1}\b/ei', "floor($1 * .1) * 10 . (($2 == 's') ? 's' : '')", $string);
  6. Well, I was trying to use your code to do something a little different. I decided to make the phrase "Tomorrow's high will be in the 36s" to "Tomorrow's high will be in the 30s" So, my query looked like this: $unit = "m"; $string = "mpdData['narr'].day['1']=new mpdNDObj(new Date('2008','7','30'),'1','A few isolated thunderstorms developing during the afternoon. High 86F. Winds light and variable. Chance of rain 30%.','Tomorrow hights will be in the 90s'');"; if ($unit == "m") { $string = preg_replace('/\b(-?\d+)([a-z]){1}\b/ei', "round(($1 - 32) / 1. . (($2 == 's') ? 's' : (($2 == 'F') ? 'C' : ''))", $string); $string = preg_replace('/\b(-?\d+)(s){1}\b/ei', "floor($1 * .1) * 10 . ($2 == 's') ? 's'", $string); echo $string; } else { echo $string; } But, it's failing. Basically I am trying to round down to the nearest 10, the ones that have an "s" beside them, so that it makes more sense.
  7. DarkWater, I was wondering, what happens if there is a negative F value denoted with a - sign?
  8. Hey man, that's awesome. Very clear now. Check your pm in a minute.
  9. Wow, that works like a champ. Converts every singe one of them. Again, thanks.
  10. If you would, that'd be awesome. In the actual string I am using, it's more complicated in that it has brackets [], single quotes '....in fact, here's an example of the actual string. mpdData['narr'].day['1']=new mpdNDObj(new Date('2008','7','30'),'1','A few isolated thunderstorms developing during the afternoon. High 86F. Winds light and variable. Chance of rain 30%.','Tomorrow'); mpdData['narr'].day['2']=new mpdNDObj(new Date('2008','7','30'),'1','Isolated thunderstorms in the evening. Fair skies overnight. Low 67F. Winds light and variable. Chance of rain 30%.','Tomorrow night'); mpdData['narr'].day['3']=new mpdNDObj(new Date('2008','7','31'),'2','Times of sun and clouds. Highs in the low 80s and lows in the mid 60s.','Sunday'); Not sure if this changes anything....but I have a feeling it will. So far I haven't gotten any output....
  11. wow man....you make that look really easy. I would have never come up with that...at least like that. now to figure out what you did Thanks!
  12. I am having trouble with putting this together in my head. Instead of explaining outright, I'm just going to give it to you by example. $string = "Today the high is 72F and the low is 36F. Tomorrow will be in the 60s." I want to convert each number there to Celsius based on an indicator from the url. I need to extract each number, convert each number, and replace each number back in the string. I figure it's going to have extract into an array, and it will require regex to find the different numbers and account for the F and s when searching. I can handle the actual conversion to Celsius, however I am not sure how to extract and replace the numbers.
×
×
  • 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.