Some simple (but useful) examples

Last modified: January 17, 2008 - 17:26

This page is a collection of simple replacement rules you can use for yourself. Before you can use any of this, you should have a filter as a container.

Simple replace (case sensitive)

This will convert all occurence of foo into bar, but it is case-sensitive, means that it won't work for Foo, or fOO.

  • Pattern: /foo/
  • PHP Code: off
  • Replacement: bar

Simple replace (case insensitive)

This will convert all occurence of foo into bar, and it is not case-sensitive, means that it will work for Foo, and fOO.

  • Pattern: /foo/i
  • PHP Code: off
  • Replacement: bar

Tag replacer

This will convert all occurence of <hello> into Hello World. It is not case sensitive, and it can handle spaces within tag, like <  hello    >, by using \s* pattern. That pattern means "zero, or more spaces here".

  • Pattern: /<\s*hello\s*>/i
  • PHP Code: off
  • Replacement: <strong>Hello World!</strong>

Links

Adds link to drupal.org on the occurence of <drupal/>. Notice that there is no \s* pattern, so it is not intended to replace <  drupal  />. You shuld enter exactly <drupal/>. And notice that backslash (\/), because slash (/) has a special meaning in regular expressions, so we must escape it using backslash.

  • Pattern: /<drupal\/>/i
  • PHP Code: off
  • Replacement: <a href="http://drupal.org">drupal.org</a>

Add some text at the top of content body

This will add BEGIN: at the top of your content body.

  • Pattern: /^/
  • PHP Code: off
  • Replacement: <strong>BEGIN:</strong><br/>

Add some text below the content body

This will add :END below your content body.

  • Pattern: /$/
  • PHP Code: off
  • Replacement: <br/><strong>:END</strong>

Auto numbering mechanism

Each <an/> will be converted into sequential number 1, 2, 3, 4, ... This replacement rule is an example of numbering mechanism.

  • Pattern: /<\s*an\s*\/>/i
  • PHP Code: on
  • Replacement:
    static $num;

    $num++;

    return $num;

More examples will be added soon.

 
 

Drupal is a registered trademark of Dries Buytaert.