<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>PS: sorry, that code was not quite right. Here it is corrected:</p>
    <p>// (strcount <needle> <HayStack>), (strcount
      <needle>), <br>
      //(strcount <needle> page=<HayStack>),(strcount
      <needle> pages=<Page1,Page2,Page3>)  <br>
      $MarkupExpr['strcount'] = 'MxStringCount($pagename, @$argp)';<br>
      function MxStringCount($pn, $argp) {<br>
          $find = $argp['find'] ?? $argp[''][0] ?? '';<br>
          if ($find=='') return '';<br>
          $pgs = $argp['pages'] ?? $argp['page'] ?? $argp[''][1] ?? $pn;<br>
          if (strpos($pgs,',')) $pages = explode(',',$pgs); <br>
          else $pages = array($pgs);<br>
          $cnt = 0;<br>
          foreach ($pages as  $p) { <br>
              $sect = strstr($p,'#'); <br>
              $name = MakePageName($pn, $p); <br>
              $source = $name.$sect;<br>
              $text = RetrieveAuthSection($pn, $source);<br>
              $cnt += substr_count($text, $find);<br>
          }<br>
          return  $cnt;<br>
      }</p>
    <div class="moz-cite-prefix">On 09/02/2026 21:52, Hans Bracker
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:1d560e59-10c1-4925-839c-50d36c4f0646@softflow.uk">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <p><font size="2">Hi Petko, I am trying to define some Markup
          Extensions which can be embedded in other MEs for use in
          calculations. I just wrote one for counting strings. It
          returns a number. But when it is inside a ME like {(sum
          (strcount  <needle>  HaystackPage)  10 )} to add 10 to
          count number  then this fails. The sum ME does not receive the
          count number from ME strcount, but a keep token. </font></p>
      <p><font size="2">I can only solve this by rewriting the 'sum' ME
          to use $params instead of $argp and add to the function at the
          top     $p = ParseArgs(MarkupRestore($params));<br>
          to get the parameters without Keep token. This seems like too 
          much code hacking in the wrong places. Is there a way that my
          strcount ME can return the value without it being made into a
          token in the ME process, so other MEs do not need to be
          hacked?</font></p>
      <p><font size="2">This is the new strcount markup expression:</font></p>
      <p><font size="2">// (strcount <needle> <HayStack>),
          (strcount <needle>), <br>
          //(strcount <needle> page=<HayStack>),(strcount
          <needle> pages=<Page1,Page2,Page3>)  <br>
          $MarkupExpr['strcount'] = 'MxStringCount($pagename, @$argp)';<br>
          function MxStringCount($pn, $argp) {<br>
              $find = $argp['find'] ?? $argp[''][0] ?? '';<br>
              if ($find=='') return '';<br>
              $pgs = $argp['pages'] ?? $argp['page'] ?? $argp[''][1] ??
          $pn;<br>
              if (strpos($pgs,',')) $pages = explode(',',$pgs); <br>
              else $pages = array($pgs);<br>
              $cnt = 0;<br>
              foreach ($pages as  $p) { <br>
                  $sect = strstr($name,'#'); <br>
                  $name = MakePageName($pn, $p); <br>
                  $source = $name.$sect;<br>
                  $text = RetrieveAuthSection($pn, $source);<br>
                  $cnt += substr_count($text, $find);<br>
              }<br>
              return  $cnt;<br>
          }</font></p>
      thanks! Hans <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre wrap="" class="moz-quote-pre">_______________________________________________
pmwiki-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:pmwiki-users@pmichaud.com">pmwiki-users@pmichaud.com</a>
<a class="moz-txt-link-freetext" href="http://www.pmichaud.com/mailman/listinfo/pmwiki-users">http://www.pmichaud.com/mailman/listinfo/pmwiki-users</a>
</pre>
    </blockquote>
  </body>
</html>