RO CSVI

Replacement: change text case

To add change the case of text you can use the Replacement feature of CSVI VirtueMart.

Since version 2.3.13.

Lowercase

Let's say you want to lowercase your product description field, here is how:

  1. Go to Replacement
  2. Make a new entry with the following settings
    • Find: /(.*)/e
    • Replace: strtolower('\1')
    • Type: Regular expression
    • Template: Select the template you use for the export
    • Field: Select the field the replacement is to be used for
    • Click on the Add icon
  3. Do an export of your template

Uppercase

Let's say you want to uppercase your product description field, here is how:

  1. Go to Replacement
  2. Make a new entry with the following settings
    • Find: /(.*)/e
    • Replace: strtoupper('\1')
    • Type: Regular expression
    • Template: Select the template you use for the export
    • Field: Select the field the replacement is to be used for
    • Click on the Add icon
  3. Do an export of your template

The magic

The magic here is the e modifier. In the Find field you put /(.*)/e, the e here is the e modifier. This allows you to use a PHP function to do something to the text found. The PHP functions used here are:

  • strtolower -> lowercase the text found
  • strtoupper -> uppercase the text found

Other PHP functions can be used, e.g.:

  • str_ireplace -> replace some string
    str_ireplace('a', 'aa', '\1') -> change all a to aa in the text found
  • substr -> take part of the string
    substr('\1', 0, 5) -> take only the first 5 letters of the text found
  • see the PHP function reference for other functions