0

Is there a way to string replace with rules?

I'm trying to find some way to transform values without changing a value entirely.

Is there something I'm missing, or should I just make a custom rule that does string replace?

17
  • If you decide to write your own custom rule, please contribute back and add it to Rules Data Transforms as that module is missing this functionality. Commented Dec 16, 2014 at 4:32
  • 1
    Look at the issue queue. There is a Remove /replace text and Capitalize functionality entry and patch. Maybe that is what you need. Commented Dec 16, 2014 at 4:37
  • 1
    I wrote a custom rule that takes token values out of a string (though it needs testing still) and which also provides actions for string replace. I'll create a sandbox for it later and use it as the answer, and also tell them at Rules Data Transform so that they can add them it to their module if they want. At the very least, the string replacer works. Commented Dec 16, 2014 at 13:15
  • 4
    Possible duplicate of How to replace text about [node:url] within a Rules Action? Commented Jun 19, 2019 at 21:18
  • 2
    @JackRyan It has an accepted answer, so your becomes the duplicate. Quality and answers are the criteria for which question becomes canonical, rather than time. Commented Jun 21, 2019 at 5:15

1 Answer 1

0

I used this for my incoming feeds, changing http:// to https://

{ "rules_http_to_https" : {
    "LABEL" : "http to https",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "php", "rules", "feeds" ],
    "ON" : { "feeds_import_canada_com" : [] },
    "DO" : [
      { "data_set" : {
          "data" : [ "node:body:value" ],
          "value" : "\u003C?php\r\necho str_replace(\u0022http:\/\/\u0022 , \u0022https:\/\/\u0022, \u0022[node:body]\u0022 );\r\n?\u003E"
        }
      },
      { "data_set" : {
          "data" : [ "node:field-contestpageurl" ],
          "value" : "\u003C?php\r\necho str_replace(\u0022http:\/\/\u0022 , \u0022https:\/\/\u0022, \u0022[node:field-contestpageurl]\u0022 );\r\n?\u003E"
        }
      }
    ]
  }
} 
1
  • 1
    Executing PHP like that is not recommended. Commented Jun 19, 2019 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.