We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25803 ☆ A M B ☆
    • 721 Posts
    Hello,

    I'm using the script in this thread:

    https://forums.modx.com/thread/80101/displaying-an-article-s-tag-as-the-page-heading#dis-post-445579

    <?php
    $pagetitle = $modx->resource->get('pagetitle');
    $get = $modx->sanitize($_GET);
    if (ISSET($get['tag'])){
        $tag=$get['tag'];
        return 'Posts tagged with'.$tag;
    }
    if (ISSET($get['arc_year'])){
        return 'Articles posted during '.date( 'F', mktime(0, 0, 0, $get['arc_month'])).' '.$get['arc_year'];
    }
    if(ISSET($pagetitle)) {
        return $pagetitle;
    }
    


    And it works fabulously for single word tags, but for a multi-word tag like: Driving Safety

    I get: Posts tagged with Driving+Safety

    Anyway to replace + signs added in the URL with   or spaces?

    This question has been answered by rx2. See the first response.

    • discuss.answer
      • 25803 ☆ A M B ☆
      • 721 Posts
      This seems to work:

      <?php
      $get = $modx->sanitize($_GET);
      if (ISSET($get['tag'])){
          $tag= preg_replace('/[^a-zA-Z0-9]+/', ' ', $get['tag']);
          return 'Posts tagged with '.$tag;
      }