Summary: link or form markup for replacing text strings in pages
Version: 2007-03-12
Prerequisites: pmwiki 2.2.0 beta
Status: beta
Categories: Editing

Questions answered by this recipe

How can I replace text strings, toggle page text variables?


Download stringreplace.phpΔ, copy to cookbook folder and install in local configuration file with:


This script enables replacing of strings in pages, by creating special replace links or input forms.

Markup syntax for replace links:

(:stringreplace str1="to be replaced" str2="replacement string":)

Optional parameters:

  • label="Replace": link text label
  • target="TargetPage": replace text on TargetPage (needs to be enabled).
  • redirect=0: do not redirect to TargetPage after replacement.

By default after replace one is redirected to TargetPage.

By default replacing is enabled for current page only.
To enable replacing for other target pages set in local config file:

$EnableStringReplaceTarget = 1;

Replacements can also be done with Input forms, using action stringreplace.


Replace toggle link for page text variable Var

(:Var:0:) Page text variable {$:Var}

(:if eq {$:Var} 0:)(:stringreplace str1=":Var:0:" str2=":Var:1:" label="Toggle Var":)
(:if eq {$:Var} 1:)(:stringreplace str1=":Var:1:" str2=":Var:0:" label="Toggle Var":)

Dummy link: Toggle Var

Input radio buttons to change page text var State

'''state: {$:State}'''
(:input form "{$PageUrl}":)
(:input hidden action stringreplace:)
(:input hidden str1 ":State:{$:State}:":)
(:input radio str2 ":State:1:":) state 1 \\
(:input radio str2 ":State:2:":) state 2 \\
(:input radio str2 ":State:3:":) state 3 \\
(:input submit post Change:)
(:input end:)

Dummy form: state: 1

State 1
State 2
State 3

Input text replace form for SideBar or RightBar

(:input form "{*$PageUrl}":)(:input hidden action stringreplace:)
replace this\\
(:input text str1 "":)\\
with this\\
(:input text str2 "":)\\
(:input submit post Replace:)
(:input end:)

Dummy form:

replace this

with this

Use check boxes to change regular occurrences to desired text

(:input form "{*$PageUrl}":)
(:input hidden action stringreplace:)
\\replace this\\
(:input checkbox str1 "}}":)}}
(:input checkbox str1 "{{":){{

\\with this\\
(:input checkbox str2 "]]":)]]
(:input checkbox str2 "[[":)((
(:input submit post Replace:)
(:input end:)

Dummy form:

replace this
}} {{

with this
]] ((


  • The script allows replacements only on pages for which the user has edit authorisation.
  • Replacing strings in target pages (using the target= parameter) is disallowed by default.
  • The page is scanned line by line for the string to be replaced. Lines with the (:stringreplace ...:) markup or (:input ..:) markup are ignored.

Release Notes

  • 2007-03-12: Fixed bug in page redirect.
  • 2007-03-11: Initial release.

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".


See Also


User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.