SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Thread: Cropping Text?

  1. #1
    SitePoint Enthusiast TheNinthPlayer's Avatar
    Join Date
    Jan 2004
    Location
    USA
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cropping Text?

    I have made myself a little script which parses an XML file from my Blog ( http://blog.theninthplayer.net/wp-rss2.php ) and post the Date and Title into an image of mine.

    An example can be seen here : http://www.theninthplayer.net/sigs/s...inthPlayer.php

    The problem is that there is unwanted text after the Date and Title. For instnace I only want the Date to look like Sat, 21 Aug 2004, thus removing the time and whatever else that is.

    Same goes for the Title. Some strange text is next to it.

    Here is my poor code
    Code:
    <?php
      $insideitem = false;
      $tag = "";
      $modified = "";
      $title = "";
    
      function startElement($parser, $name, $attrs) {
        global $insideitem, $tag, $modified, $title;
        if ($insideitem) {
          $tag = $name;
        } elseif ($name == "ITEM") {
          $insideitem = true;
        }
      }
    
      function endElement($parser, $name) {
        global $insideitem, $tag, $modified, $title;
        if ($name == "ITEM") {
    
          Header("Content-Type: image/gif");
    
          $image = ImageCreateFromGif("sig-TheNinthPlayer-php.gif");
    
          $black = ImageColorAllocate($image, 255, 255, 255);
    
          ImageString($image, 3, 48, 90, $modified, $black);
          ImageString($image, 3, 48, 104, $title, $black);
    
          ImageGif($image);
          ImageDestroy($image);
    
          $modified = "";
          $title = "";
    
          $insideitem = false;
        }
      }
    
      function characterData($parser, $data) {
        global $insideitem, $tag, $modified, $title;
        if ($insideitem) {
          switch ($tag) {
            case "PUBDATE":
              $modified .= $data;
              break;
            case "TITLE":
              $title .= $data;
              break;
          }
        }
      }
    
      // XML Blog Parser
      $xml_parser = xml_parser_create();
      xml_set_element_handler($xml_parser, "startElement", "endElement");
      xml_set_character_data_handler($xml_parser, "characterData");
    
      // Read the file
      $fp = fopen("http://blog.theninthplayer.net/wp-rss2.php","r") or die("Error reading XML data.");
      while ($data = fread($fp, 4096)) {
        xml_parse($xml_parser, $data, feof($fp)) or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
      }
    
      //Close the file
      fclose($fp);
    
      // Free up the parser
      xml_parser_free($xml_parser);
    ?>
    Any help is greatly appreciated!
    Attached Files Attached Files


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •