CaRP Evolution Documentation
CaRP Evolution Documentation
twitter youtube linkedin google-plus
CaRP Evolution Box
Web This Site

CaRP: Caching RSS Parser - Documentation

CaRP Interactive FAQ
Getting Started: Free Download | Purchase | Install
Reference: Functions | Plugins | Themes | Full Index
Etc.: Display Formatting | Example Code | Affiliates

JavaScript Output Example

Converting RSS to JavaScript:

If you are already exporting an RSS feed and would like to make it accessible to more webmasters, you can use CaRP to convert it to a JavaScript. This will enable websites that don't have the capability to import RSS newsfeeds or whose webmasters don't know how to do so to easily import your newsfeed with a single line of HTML code.

Be aware that since the remote website will not cache your JavaScript formatted feed (which they would hopefully, though not necessarily, be doing if they import your RSS formatted feed), this method will use more of your server's bandwidth to serve up your newsfeed to each person who visits their site. For this reason, we strongly recommend urging webmasters subscribing to your newsfeed to use a caching RSS parser, like CaRP, whenever possible.

To use CaRP to convert a newsfeed to JavaScript, create a PHP file like the following:

require_once "/www/shared/carp.php";

It will then be possible to import your newsfeed into any webpage by adding HTML code like the following to that page:

<script src=""></script>

In the preceding example, the person importing your newsfeed has no control over it's appearance. By creating a more complex PHP page on your site, you can allow them to decide how many news items to display, as well as a number of other formatting options. Notice how this code provides default values in case the webmaster doesn't specify anything.

Note that no cache file is specified in the call to CarpShow. This is important, because the formatting may be different each time this page is loaded. Since you are formatting a local RSS feed in this case, this will not affect performance the way it would with a remote newsfeed.

require_once "/www/shared/carp.php";

function GetParam($name,$default='',$isNum=0) {
   if ($isNum) $val+=0;
   else $val=preg_replace("/[^a-zA-Z0-9. ]/",'',$val);
   return $val;


if (($doClass=strlen($hbc))||$hbw) {
   CarpConf('bilink','<div '.
      ($doClass?"class=\"$hbc\" ":'').
      ($doClass?'':(';background:#ccc;padding:2px;border:1px solid #333;')).
if (strlen($hc)) CarpConf('ilinkclass',$hc);


The following HTML code will import a newsfeed from the above PHP file showing a maximum of 8 items, no description fields, using a CSS class defined by the subscribing website (myHead) to set the formatting of the links. Webmasters will be able to set these and other options enabled by your PHP code.

<script src=""></script>

To help webmasters configure the appearance of your newsfeed, you may also wish to provide a file like the following:

<html><head><title>Format newsfeed</title>
function UpdateScript() {
   if (df.mi.value!=15) u='?mi='+df.mi.value;
   if (df.hc.value.length)
      u=u+(u.length?'&':'?')+'hc='+df.hc.value.replace(' ','+');
   if (df.hbc.value.length)
      u=u+(u.length?'&':'?')+'hbc='+df.hbc.value.replace(' ','+');
   if (df.hbw.value!=0)
   if (nw) u=u+(u.length?'&':'?')+'nw='+nw;
   df.s.value='<'+'script src="'+
</head><body bgcolor="white">

<form name="f" action="javascript:a=1;" method="post">
Add this HTML to your web page:<p>
<textarea name="s" rows="2" cols="80" wrap="virtual">&lt;script

To customize the formatting, use the following form:<br>
Maximum items to display:
   <input name="mi" size="3" value="15" onKeyUp="UpdateScript();"><br>
Headline display:<br>
   &nbsp;&nbsp;&nbsp;CSS class for link:
      <input name="hc" size="10" onKeyUp="UpdateScript();">
      (optional - defined in your stylesheet)<br>
   &nbsp;&nbsp;&nbsp;CSS class for box surrounding headline:
      <input name="hbc" size="10" onKeyUp="UpdateScript();">
      (optional - defined in your stylesheet)<br>
   &nbsp;&nbsp;&nbsp;Width of box surrounding headline:
      <input name="hbw" size="4" onKeyUp="UpdateScript();">
When user clicks headline, follow link in:
   <select name="nw" onchange="UpdateScript();">
   <option selected value="0">the current browser window
      (and frame, if applicable)
   <option value="1">a new window
   <option value="2">the top frame of current browser window

The address of the RSS newsfeed is