Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Need Help with Coding Line Spaces

    Good Evening All,

    I am trying to properly code my twitter posts into my webpage. The idea is to give users a way to reach me on a more personal level. I have changed all the meaninful values a novice could. I have much more knowledge with html and none whatsoever with php.

    When I set the value for multiple twitters to display, all of the messages are jumbled into one long string of sentences. I need a way to separate one display from the next.

    I would appreciate any input from the more experienced coders.

    Thank you!

    Here is the PHP code I am using. Currently I have set the value to one to prevent the aforementioned jumbling:

    Code:
    <?php
    
    function get_twitterRSS() {
    	$rss_url = 'http://twitter.com/statuses/user_timeline/******.rss';
      $home_url = 'http://twitter.com/*****';
      // NOTE: this isn't _really_ your username, it's whatever shows up before
      // the colon before your twitters (for me it's "Michael Malone", my real name)
    	$username = "*****";
      // Number of twitters to display
    	$num_items = 1;
      // HTML or text to display before and after each twitter
    	$before = "";
    	$after = "";
      // If false, twitters will link back to their respective pages on twitter.com
    	$hide_links = true;
      // If true your username (above) will be stripped from each twitter
    	$hide_username = true;
      // If true, your twitters will be trimmed to the length in trim_count below
      $trim = true;
      $trim_count = 160;
      // Trimmed twitters will have this string appended to them
      $trim_marker = '..&raquo;';
      // If true, the trim marker will link back to the twitter 
      $trim_link = true;
      // Replace urls (http://<something>) with links to that URL
      $url_replace = true;
      // Replace username in @replies with a link to that user's twitter page
      $reply_replace = true;
    
      $url_regex = '{
            \b
            # Match the leading part (proto://hostname, or just hostname)
            (
              # ftp://, http://, or https:// leading part
              (http)://[-\w]+(\.\w[-\w]*)+
            |
              # or, try to find a hostname with more specific sub-expression
              (?i: [a-z0-9] (?:[-a-z0-9]*[a-z0-9])? \. )+ # sub domains
              # Now ending .com, etc. For these, require lowercase
              (?-i: com\b
                  | edu\b
                  | biz\b
                  | gov\b
                  | in(?:t|fo)\b # .int or .info
                  | mil\b
                  | net\b
                  | org\b
                  | [a-z][a-z]\.[a-z][a-z]\b # two-letter country code
              )
            )
    
            # Allow an optional port number
            ( : \d+ )?
    
            # The rest of the URL is optional, and begins with /
            (
              /
              # The rest are heuristics for what seems to work well
              [^.!,?;"\'<>()\[\]\{\}\s\x7F-\xFF]*
              (
                [.!,?]+ [^.!,?;"\'<>()\[\]\{\}\s\x7F-\xFF]+
              )*
            )?
          }ix';
    
    	if (!function_exists('MagpieRSS')) { // Check if another plugin is using RSS, may not work
    		include_once (ABSPATH . WPINC . '/rss.php');
    		error_reporting(E_ERROR);
    	}
    
    	# get rss file
    	$rss = @fetch_rss($rss_url);
    
    	if ($rss) {
        $descmatches = "";
        # specifies number of entries
    		$items = array_slice($rss->items, 0, $num_items);
    		$username = $username .": ";
    		
    	  # builds html from array
       	foreach ( $items as $item ) {
          $description = $item['description'];
         
          if ($hide_username) {
            $twitter = str_replace($username,'', $description);
          }
               
        $twitter = htmlspecialchars(stripslashes($twitter));
    	       
        if($trim) {
          $t = mb_strimwidth($twitter, 0, $trim_count - strlen(html_entity_decode($trim_marker)), '', 'UTF-8');
    
          // Trim last word, replace with trim marker...
          if($t != $twitter) {
            // Trim link only works if you're hiding your link
            if($trim_link && $hide_links) {
              $url = $item['link']; 
              $trim_marker = "<a href='$url'>$trim_marker</a>";
            }
            $t = preg_replace('/[\W\s]*\w*[\W\s]*$/', '', $t);
            $trimmed = true;
          }
    
          $twitter = $t;
        }
    
        // URL Replace only works if you're hiding your link
        if($url_replace && $hide_links) {
          $twitter = preg_replace($url_regex, '<a href="$0">$0</a>', $twitter); 
        }
    
        // Reply replace only works if you're hiding links
        if($reply_replace && $hide_links) {
          $twitter = preg_replace('!^@([^ ]+)!', '@<a href="http://twitter.com/$1">$1</a>', $twitter);
        }
    
        // Add the trim marker (couldn't add before b/c url_replace would do a double href)
        if($trimmed) {
          $twitter .= $trim_marker;
        }
    
          if (!$hide_links) { 
            $url = $item['link']; 
            print $before . "<a href=\"$url\" title=\"Permanent link\">$twitter</a>" . $after; 
          } else { 
            print $before . $twitter . $after; 
          }
        } // end foreach
      } else {
        #print "Something went wrong.";
      }
    } # end get_twitterRSS() function
    ?>

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    As far as I can tell you must enter a value into these two variables. <br> should do the trick, or for a line <hr>, or anything you want to separate the posts.
    PHP Code:
     // HTML or text to display before and after each twitter
        
    $before "";
        
    $after ""
    Those two variables are for the print statement in the foreach loop
    PHP Code:
       print $before "<a href=\"$url\" title=\"Permanent link\">$twitter</a>" $after
          } else { 
            print 
    $before $twitter $after

    ---------------
    Leonard Whistler

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Problem solved. Simple but I would not have thought to enter line breaks in that space. I kept figuring putting words in there would look stupid.

    Thank you for the help!


  •  

    Posting Permissions

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