RO CSVI

Replacements

Replacements

Requirements

  • CSVI Pro 6.0+
  • Joomla 3.4.3+
  • PHP 5.4

Background information

The replacement feature can be used to change data during export or before import.

Types of replacements

There are 2 types of replacements that can be done:

  • Regular text
  • Regular expressions

Regular text

A regular text replacement is a simple replacement where value x gets replaced with value y. For example replace NL with Netherlands. Any text found to match NL is being replaced with Netherlands.

Regular expressions

A regular expression replacement is a more advanced replacement using regular expressions. For example you can add extra text to the end of a field.

Creating replacement rules

From Components -> CSVI pro ->Templates tab -> Rules, Click New to add a new rule using replace plugin.

For example to create a rule to replacing text "NL" to "Netherlands"  in  virtuemart product description.

  1. Give a descriptive name for the rule in name field
  2. Select Action as Import
  3. Select Plugin as CSVI Replace
  4. Click on load plugin button

Find

Give here the text that CSVI needs to look for. When doing:

  • A regular text replacement the text here is just plain text for example NL.
  • A regular expression replacement the text here needs to be enclosed in forward slashes for example /NL/

It is possible to look for and replace multiple values in 1 replacement rule. Multiple values must be separated by a pipe symbol. When doing:

  • A regular text replacement the text is only separated by a pipe symbol for example NL|DE|US
  • A regular expression replacement each text is enclosed in forward slashes for example /NL/|/DE/|/US/
Replace

Give here the text CSVI needs to use for replacement for example Netherlands. Multiple values must be separated by a pipe symbol for example Netherlands|Germany|United States.

Multiple values

If your find and replace contains multiple values to look for, set this to Yes so all values will be searched for and replaced independently.

Method

Specify here if CSVI should do a regular text or a regular expression replacement

Examples

Add text at beginning of a value

This example adds the text Before to the value found

Find: /^/
Replace: Before
Method: Regular expression

Add text at the end of a value

This example adds the text After to the value found

Find: /$/
Replace: After
Method: Regular expression

Change text to lowercase

This changes the value to lowercase

Find: /(.*)/e
Replace: strtolower('\1')
Method: Regular expression

This will not work with PHP 7 and higher. CSVI 6.7.0 will have a new rule plugin that makes this possible.

Change text to uppercase

This changes the value to uppercase

Find: /(.*)/e
Replace: strtoupper('\1')
Method: Regular expression

This will not work with PHP 7 and higher. CSVI 7.0 will have a new rule plugin that makes this possible.

Change first letter to uppercase

This changes the first letter of the value to uppercase, if that letter is alphabetic

Find: /(.*)/e
Replace: ucfirst('\1')
Method: Regular expression

This will not work with PHP 7 and higher. CSVI 7.0 will have a new rule plugin that makes this possible.

Replace text

This replaces all occurences of a with aa in the value

Find: /(.*)/e
Replace: str_ireplace('a', 'aa', '\1')
Method: Regular expression

This will not work with PHP 7 and higher. CSVI 7.0 will have a new rule plugin that makes this possible.

Take part of the value

This takes the first 5 characters of the value

Find: /(.*)/e
Replace: substr('\1', 0, 5)
Method: Regular expression

This will not work with PHP 7 and higher. CSVI 7.0 will have a new rule plugin that makes this possible.