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
Getting Started: Free Download | Purchase | Install
Reference: Functions | Plugins | Themes | Full Index
Etc.: Display Formatting | Example Code | Affiliates
Replace Text
Replace Text is a plugin bundled with CaRP Evolution. It enables you to modify the contents of a newsfeed before display. Use it to expand acronyms, add bold or italics to certain words or phrases, "bleep" language you don't want appearing on your site, etc. NOTE: If using the Replace Text plugin with someone else's feed, you are responsible to ensure that you are not violating the publisher's copyright rights.IMPORTANT NOTE: Altering the contents of a newsfeed may violate copyrights or have other legal consequences. It is your responsibility to ensure that your use of this plugin is legal. You may wish to contact the publisher of a newsfeed to obtain permission before using this plugin to modify it.
Installation:
To install Replace Text, put replacetext.php into the "plugins" folder inside the folder containing carp.php. (If no plugins folder exists, create one.)
Use:
To use this plugin, do the following:
- Enter the following command into your webpage after "require_once '/path/to/carp.php';":
CarpLoadPlugin('replacetext.php'); - For any text you wish to modify, use one of the following functions (you may repeat this step more than once):
- ReplaceTextConf($initem, $field_name, $is_regular_expression, $search_text, $replace_text);
This function alters the text after CaRP has applied any "before", "after" and other settings to it.- $initem: 0 if you want to modify data in the channel section of the newsfeed, 1 to modify data in individual items.
- $field_name: The name of the field to modify (using CaRP's internal field names). You may leave the field blank to modify all fields. Valid values are: title, link, url, image, date, author, and desc.
- $is_regular_expression: 0 if you wish to search for an exact match to the text you specify, or 1 if your search string is a regular expression.
- $search_text: The text or regular expression to search for.
- $replace_text: The text to replace $search_text with.
- ReplaceTextConf2($initem, $field_name, $is_regular_expression, $search_text, $replace_text);
This function (available in CaRP Evolution 4.0 and higher only) alters the text before CaRP has applied any "before", "after" or other settings to it. Otherwise, it is identical to ReplaceTextConf.
- ReplaceTextConf($initem, $field_name, $is_regular_expression, $search_text, $replace_text);
Example:
To replace "IMHO" with "in my humble opinion", and bold the word "evolution", when either occurs in item descriptions, do the following:
ReplaceTextConf(1,'desc',0,'IMHO','in my humble opinion'); ReplaceTextConf(1,'desc',1,'(evolution)','<b>\\1</b>');Note that when $is_regular_expression is 0, the matching is case sensistive. When using regular expressions, the match is not case sensitive. In the second example, "\\1" inserts the text that matched the text in parenthesis in $search_text. The example uses this style rather than ReplaceTextConf(1,'desc',1,'evolution','<b>evolution</b>'); to ensure that the case of the text is not changed (for example, from "Evolution" to "evolution").