Last updated November 8, 2011. Created by zeta ζ on January 14, 2008.
Edited by jhodgdon, sillygwailo, kiamlaluno. Log in to edit this page.
Temporary place-holders and delimiters
When writing a content filter module, or any code that processes or modifies content, it is tempting to use an obscure character as a place-holder, especially if only your code will see it: But this cannot be guaranteed. Non-printing, invalid or undocumented characters might not be handled correctly in the unlikely event that they are seen by a browser or feed-reader. And the more unlikely they are to be seen – the less likely they are to be tested. This will mean that some code will be written to find and eradicate these insidious characters, possibly including the ones your code is using to do its work.
To avoid this happening, and extending the lifetime of your code, please use an appropriate alpha-numeric string – prefixed by the name of the module (as a name-space) and a hyphen - or underscore _ – and surrounded by […].
If you need delimiting place-holders, the closing delimiter can incorporate a / after the initial [ and may suffix the modulename.
Finding your placeholders
A PCRE such as
'@\[modulename-tag\](.+?)\[/modulename-tag\]@'
or
'@\[modulename-tag\](.+?)\[/tag-modulename\]@'if you suffixed the modulename as mentioned above
can be used to match the string you have previously delimited.
Comments
what?
I've missed the point of what this page is talking about. Placeholders and delimiters... where? What's the use case? An example would help.
Content Filters
Reading this Book Page again, I can see your point.
See filter_example in Examples for Developers. The comment for
function _filter_example_filter_time_prepare()has a reference to this Book Page.I’ll update this page to clarify…
___________________
It’s in the detaιls…
Chessboard example
I definitely understand your confusion Andrew. This whole concept of filters is another area where there is a lot of terminology which takes a while to get hold of.
Here is a (hopefully) simple example. In the Chessboard module, you can set things up so that you can add a chessboard to your page using the standard text format for chessboards (Forsyth-Edwards Notation), e.g.:
[chessboard]4k3/pppppppp/8/8/4P3/8/PPPP1PPP/4K3[/chessboard]
Then, when the page is displayed, instead of showing this difficult to read text format, the module displays a beautiful graphical rendering of a chessboard.
The filters example in the Examples module gives 2 great examples of what is possible with filters (and the code for developers of how to do it):
<time />and have it replaced by the current timeThe point of this page here (I think) is to say that such delimiters as [chessboard] should be done using the format described above.
drupalshrek
Maintainer of the VChess module visible in use at chess website Chesspos.com
Regex clarification please
With regards to the second example, would anyone explain the regexp used in there?
preg_replace('!<time ?/>!', '[filter-example-time]', $text);What exactly do the exclamation marks mean?
delimiters
http://uk.php.net/manual/en/regexp.reference.delimiters.php being an exclamation mark is less important than that they are both the same.
___________________
It’s in the detaιls…