Jump to content

invictive

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

invictive's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok, I seem to have got it working ok, this is what I have: $string = preg_replace('~(Sunday+):[^<]+~i','$1',$string); $string = preg_replace('~(Sunday Night+):[^<]+~i','$1',$string); $string = preg_replace('~(Monday+):[^<]+~i','$1',$string); $string = preg_replace('~(Monday Night+):[^<]+~i','$1',$string); $string = preg_replace('~(Tuesday+):[^<]+~i','$1',$string); $string = preg_replace('~(Tuesday Night+):[^<]+~i','$1',$string); $string = preg_replace('~(Wednesday+):[^<]+~i','$1',$string); $string = preg_replace('~(Wednesday Night+):[^<]+~i','$1',$string); $string = preg_replace('~(Thursday+):[^<]+~i','$1',$string); $string = preg_replace('~(Thursday Night+):[^<]+~i','$1',$string); $string = preg_replace('~(Friday+):[^<]+~i','$1',$string); $string = preg_replace('~(Friday Night+):[^<]+~i','$1',$string); $string = preg_replace('~(Saturday+):[^<]+~i','$1',$string); $string = preg_replace('~(Saturday Night+):[^<]+~i','$1',$string); $string = preg_replace('~(Current Conditions+):[^<]+~i','$1',$string); does that look ok, is there anything I should do to clean it up a bit? Thanks! -invictive
  2. Hi guys, I'm fairly new to php and am having a bit of trouble modifying a script. This is the script: <?php ############################################################################# # Local weather by zip code # # Aastra SIP Phones 1.4.2 or better # # Copyright 2008 Aastra Telecom Ltd # # Copyright (C) 2001, Joseph Harris # cdi@thewebmasters.net # http://www.thewebmasters.net/ # # Supported Aastra Phones # All phones but best on # 480i # 480iCT # 35i # 35i CT # 55i # 57i # 57i CT # # script.php?zip=XXXXX # where XXXXX is the US ZIP code of the city (optional) # ############################################################################# ############################################################################# # PHP customization for includes and warnings ############################################################################# $os = strtolower(PHP_OS); if(strpos($os, "win") === false) ini_set('include_path',ini_get('include_path').':include:../include'); else ini_set('include_path',ini_get('include_path').';include;..\include'); error_reporting(E_ERROR | E_PARSE); ############################################################################# # Includes ############################################################################# require_once('RSS.class.php'); require_once('AastraCommon.php'); require_once('AastraIPPhoneInputScreen.class.php'); require_once('AastraIPPhoneTextMenu.class.php'); require_once('AastraIPPhoneTextScreen.class.php'); ############################################################################# # Private functions ############################################################################# # trim_title function function trim_title($string,$before,$after) { # Process Before if($before!="") { $array=explode($before,$string,2); $string=$array[1]; } # Process after if($after!="") { $array=explode($after,$string,2); $string=$array[0]; } return($string); } # filter_format function function filter_format($string) { # Process Before $string = preg_replace('~([a-z]+):.+\.~i','$1',$string); # Remove All HTML crap $search = array ('@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@([\r\n])[\s]+@', // Strip out white space '@&(quot|#34);@i', // Replace HTML entities '@&(amp|#38);@i', '@&(lt|#60);@i', '@&(gt|#62);@i', '@&(nbsp|#160);@i', '@&(iexcl|#161);@i', '@&(cent|#162);@i', '@&(pound|#163);@i', '@&(copy|#169);@i', '@&(#xB0);@i', '@&#(\d+);@e'); // evaluate as php $replace = array ('', '', '\1', '"', '&', '<', '>', ' ', chr(161), chr(162), chr(163), chr(169), chr(176), 'chr(\1)'); $string = preg_replace($search, $replace, $string); $string = preg_replace($search, $replace, $string); $string = preg_replace('/\n/',' ', $string); return($string); } ############################################################################# # Beginning of the active code ############################################################################# # Collect parameters $header=Aastra_decode_HTTP_header(); $user=Aastra_getvar_safe('user',$header['mac']); $index=Aastra_getvar_safe('index'); $zip=Aastra_getvar_safe('zip'); # Trace Aastra_trace_call('weather','zip='.$zip.', index='.$index); # Test User Agent Aastra_test_phone_version('1.4.2.',0); # Get Language $language=Aastra_get_language(); # Input ZIP code if($zip=='') { $object = new AastraIPPhoneInputScreen(); $object->setTitle(Aastra_get_label('Canadian Weather',$language)); $object->setPrompt(Aastra_get_label('Enter ENVCAN code',$language)); $object->setParameter('zip'); $object->setType('string'); $object->setURL($XML_SERVER."?user=".$user); $object->setDestroyOnExit(); $data=Aastra_get_user_context($user,'weather'); if($data['last']!=NULL) $object->setDefault($data['last']); $object->output(); exit; } # Save last value requested $data['last']=$zip; Aastra_save_user_context($user,'weather',$data); # Test if we need to regenerate the static pages $generate=0; $file_name=AASTRA_PATH_CACHE."w-".$zip.".rss"; if(!file_exists($file_name)) $generate=1; else { if(time()-filemtime($file_name)>(4*900)) $generate=1; } # If need to generate if($generate==1) { # Check if target directory is present if (!is_dir(AASTRA_PATH_CACHE))@mkdir(AASTRA_PATH_CACHE); # Open and retrieve RSS XML file $handle = @fopen("http://www.weatheroffice.gc.ca/rss/city/".$zip.".xml", "r"); if($handle) { while ($line=fgets($handle,1000)) $data.=$line; fclose($handle); } else { Aastra_debug('Can not open URL in read mode'); $object = new AastraIPPhoneTextScreen(); $object->setTitle(Aastra_get_label('Information not available',$language)); $object->setText(Aastra_get_label('The information you are looking for is not available at this time. Try again later.',$language)); $output=$object->output(); exit; } # Process RSS feed $rss = new RSS ($data); $allItems = $rss->getAllItems(); $itemCount = count($allItems); # ZIP code OK? if($itemCount!=0) { # Prepare static file $handle = @fopen($file_name,"w"); if($handle) { for($y=0;$y<$itemCount;$y++) { # Format data fputs($handle,"[".$y."]\n"); $allItems[$y]['TITLE']= filter_format($allItems[$y]['TITLE']); $allItems[$y]['TITLE']= trim_title($allItems[$y]['TITLE'],""," :: "); if($y==0) { $main=$allItems[$y]['TITLE']="Victoria, BC"; $allItems[$y]['TITLE']="Watches and Warnings"; } fputs($handle,"title=".$allItems[$y]['TITLE']."\n"); $description=filter_format($allItems[$y]['DESCRIPTION']); if(trim($description," ")=="") $description=Aastra_get_label("No data provided",$language); $allItems[$y]['DESCRIPTION']= $description." ".Aastra_get_label("",$language); fputs($handle,"description=".$allItems[$y]['DESCRIPTION']."\n"); fputs($handle,"uri=".$XML_SERVER."?zip=".$zip."&index=".($y+1)."\n"); } fputs($handle,"[99]\n"); fputs($handle,"title=".$main."\n"); fclose($handle); } else { Aastra_debug("Can not open ".$file_name." in write mode"); $object = new AastraIPPhoneTextScreen(); $object->setTitle(Aastra_get_label('Information not available',$language)); $object->setText(Aastra_get_label('The information you are looking for is not available at this time. Try again later.',$language)); $output=$object->output(); exit; } } else { Aastra_debug("RSS feed empty, wrong ENVCAN code"); $object = new AastraIPPhoneTextScreen(); $object->setTitle(Aastra_get_label('Error',$language)); $object->setText(Aastra_get_label('No data available, please check the ENVCAN code you entered.',$language)); $output=$object->output(); exit; } } # Display the requested article or list $array_rss=Aastra_readINIfile($file_name,'#','='); if (empty($index)) { # Display list $object = new AastraIPPhoneTextMenu(); $object->setTitle($array_rss[99]['title']); if(Aastra_is_style_textmenu_supported()) $object->setStyle('radio'); foreach ($array_rss as $key=>$value) { if($key!='99') $object->addEntry($value['title'],$value['uri']."&user=".$user); } $object->addSoftkey('4', Aastra_get_label('Select',$language), 'SoftKey:Select'); $object->addSoftkey('5', Aastra_get_label('Back',$language), $XML_SERVER."?user=".$user); $object->addSoftkey('6', Aastra_get_label('Exit',$language), 'SoftKey:Exit'); } else { # shift $index $index--; # Display article $object = new AastraIPPhoneTextScreen(); $object->setDestroyOnExit(); $object->setTitle($array_rss[$index]['title']); $object->setText($array_rss[$index]['description']); if($index!=0) $object->addSoftkey('4', Aastra_get_label('Previous',$language), $XML_SERVER."?zip=".$zip."&index=".$index."&user=".$user); if($index!=(count($array_rss)-2))$object->addSoftkey('5', Aastra_get_label('Next',$language), $XML_SERVER."?zip=".$zip."&index=".($index+2)."&user=".$user); $object->addSoftkey('6', Aastra_get_label('Exit',$language), 'SoftKey:Exit'); } # Display output $object->output(); exit; ?> An example of what the RSS feed looks like: http://www.weatheroffice.gc.ca/rss/city/bc-85_e.xml The script downloads an RSS weather feed, parses it and displays it on my IP Phone. What I am trying to do is to grab a couple of different variables and then print them later on. I am trying to grab the name of the city from the RSS feed, the name of the province from the filename of the RSS feed, and the language from the filename of the RSS feed. The feed that it displays is variable, the $zip syntax specifies which rss feed to download. $zip is in the following formant: xx-xxx_x where: xx=the province, xxx=the city code, x=the language. So I want to grab the xx (province) from the filename, and capitalize it, ie: BC. I want to grab the city from the rss file ie: Vancouver and the language from the RSS filename, ie: f for french and e for english. I then want to be able to print these variables later in the script, ie: $city = Victoria, BC I also want to be able to display a different text depending on the language, ie: if f(french) then print: Conditions météo actuelles if e(english) print: Current weather conditions and be able to print that with: $titlelang I know im asking a lot, but if anyone can point me in the right direction it would be greatly appreciated. Thanks a lot! -invictive
  3. Thanks guys, $string = preg_replace('~([a-z]+):.+\.~i','$1',$string); seemed to do the trick, however I noticed that sometimes the string is different. I will attach the files to properly demonstrate what I mean. The RSS file that the script is grabbing and parsing: http://www.weatheroffice.gc.ca/rss/city/bc-85_e.xml The output file as the script is currently configured: http://pastebin.ca/1690436 The script: http://pastebin.ca/1690431 As you can see sometimes the string is different and there is more data. Is there any way to have it keep everything before the : (the day) and remove everything after? (including the thanks a lot, -invictive
  4. Hi guys, I'm trying to edit a php file that grabs the weather from an RSS feed and formats it for my phone. I want it to search for the following string: Sunday: XXXXX Low XX. High XX. and strip everything between the first : and the final . The XXX are variables. So it would simply return: Sunday I can get it to replace static text, but I have no idea how to get it to replace data with wildcards. So far all I have is: $string=preg_replace(array("/Sunday: /","/Sunday: /"), array("Sunday","Sunday"), $string); but all that does is replace Sunday: with Sunday, it still leaves all the crap after it. Any help would be greatly appreciated, Thanks, invictive
×
×
  • 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.