Truncating Permalinks That Are Displayed for RSS Feed Generated WordPress Posts

I am setting up an aggregator WordPress site that automatically generates syndicated posts from the content of selected RSS feeds.

My problem lies with the WordPress permalinks for these syndicated posts -- which point to the original content source pulled from the RSS feed.  In almost all instances, these permalink strings are very lengthy. For example:

http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNFaVkQwfdbun9VrpA09iD38219-jg&url=http://www.cbsnews.com/8301-501708_162-57354545/fsjkalaksniwnrognmsldm7wglv-televised-debate/

My WordPress theme uses the following code to display the permalink string (as plain text):

<cite><?php the_permalink() ?> - </cite>

Open in new window


I would like to set a character limit on the length of the Permalink string that is displayed, so the displayed string is truncated, with "..." affixed at the end.  So the Permalink example listed above would be transformed into something like this:

http://news.google.com/news/url?sa=t&fd=R&...

Any assistance would be greatly appreciated.
JorhalAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
http://www.laprbass.com/RAY_temp_jorhal.php outputs
http://news.google.com/news/url?sa=t&fd=R&...
<?php // RAY_temp_jorhal.php
error_reporting(E_ALL);

// SHOW WHERE &fd=R& OCCURS AT POSITION 42       |
//                                               V
//      1...5...10...15...20...25...30...35...40...45...
$url = 'http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNFaVkQwfdbun9VrpA09iD38219-jg&url=http://www.cbsnews.com/8301-501708_162-57354545/fsjkalaksniwnrognmsldm7wglv-televised-debate/';

// MAKE THE DISPLAY PORTION OF THE URL
$txt = substr($url,0,42) . '...';

// CREATE THE LINK
$lnk
= '<a '
. 'class="off" '
. 'target="_blank" '
. 'href="'
. $url
. '">'
. $txt
. '</a>'
;

// WRITE THE LINK
echo $lnk;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.