topical media & game development

talk show tell print

student-twitter-admin-xmlfunctions.incl.php / php



  <?php
          function getFromXML (filename)        {
                  lines = file(filename);
                  
                  result = Array();
                  foreach(lines as line) {
                          if ( strstr(line, "<emotion name=") ) {
                                  entry = Array();
                                  
                                  temp = explode("\"", line);
                                  entry[0] = temp[1];
                          } else if ( strstr(line, "<color") ) {
                                  temp = explode("\"", line);
                                  entry[1] = Array(temp[1], temp[3], temp[5]);
                          } else if ( strstr(line, "<word>") ) {
                                  temp = explode(">", line);
                                  temp = explode("<", temp[1]);
                                  entry[2][] = temp[0];
                          } else if ( strstr(line, "</emotion>") ) {
                                  result[] = entry;
                          }
                  }
                  return result;
          }
          
          function toXML (entries)        {
                  result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<emotions type=\"array\">\n";
                  foreach(entries as entry) {
                          result .= "\t<emotion name=\"".entry[0]."\">\n";
                          result .= "\t\t<color red=\"".entry[1][0]."\" green=\"".entry[1][1]."\" blue=\"".entry[1][2]."\"/>\n";
                          result .= "\t\t<words>\n";
                          foreach(entry[2] as word) {
                                  result .= "\t\t\t<word>word</word>\n";
                          }
                          result .= "\t\t</words>\n";
                          result .= "\t</emotion>\n";
                  }
                  result .= "</emotions>";
                  return result;
          }
          
          function saveToFile ( filename, content ) {
                  fp1 = @fopen( filename, "w" );
                  lines = explode("\n", content);
                  foreach(lines as line) {
                          fp2= fputs( fp1, line."
  " );
                  }
                  fp2= fclose( fp1 );
          }
  ?>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.