Process plugin: substr

Last updated on
22 June 2017

The substr plugin is used to return part of a string.

process:
  new_text_field:
    plugin: substr
    source: some_text_field
    start: 6
    length: 10

If some_text_field was 'Marie Skłodowska Curie' then $destination['new_text_field'] would be Skłodowska.

The PHP equivalent of this would be:

$destination['new_text_field'] = substr($source['some_text_field'], 6, 10)

If start is NULL and length is an integer, the start position is the beginning of the string.
If length is NULL and start is an integer, the substring starting from the start position until the end of the string will be returned.
If both start and length are NULL the entire string is returned.

The substr plugin requires, that value is not empty. If empty values are expected, use skip_on_empty to skip the process:

process:
  new_text_field:
    -
      plugin: skip_on_empty
      method: process
      source: some_text_field
    -
      plugin: substr
      source: some_text_field
      start: 6
      length: 10