Using token_replace in php filter with webform2pdf I'm trying to use submission id of webform in webform2pdf.

My problem it is possibility of usage result of token_replace in php filter.

&lt;?php
  $node = node_load(53470);
  $sid_token = '[submission:sid]';
  $sid = token_replace($sid_token, array('node' =&gt; $node));
  print 'strlen($sid) = '. strlen($sid);
  foreach (str_split($sid) as $position =&gt; $symbol) {
    print 'Position ' . $position . ', symbol ' . $symbol . '&lt;br&gt;';
  }
  print 'echo($sid) = '; echo($sid);
?&gt;


[submission:sid] must return string '145', but result is:

strlen($sid) = 16

Position 0, symbol [
Position 1, symbol s
Position 2, symbol u
Position 3, symbol b
Position 4, symbol m
Position 5, symbol i
Position 6, symbol s
Position 7, symbol s
Position 8, symbol i
Position 9, symbol o
Position 10, symbol n
Position 11, symbol :
Position 12, symbol s
Position 13, symbol i
Position 14, symbol d
Position 15, symbol ]

echo($sid) = 145


As I understand it means that token_replace function is called after php filtered expression execution but I need to use result of $sid inside php

&lt;?php $submission = webform_get_submission(53470, $sid); ?&gt;
When you use token_replace(), you need to provide it with a proper data array. Since you provide it with a node, your token replace can only replace [node:*] tokens (exceptions for global tokens such as [site:*]). If your submission is a node, you should be able to use [node:nid] instead.

If you were to use $sid = token_replace($sid_token, array('submission' =&gt; $node));, you can use tokens like [submission:*], but only with node properties (nid instead of sid).

If your submission is of another entity type, you will have to provide that as data as well.