We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3071
    • 99 Posts
    This is no different from the last one, it still adds 9 href links to my page. It also seems to make the line under my clickable keyword 2 characters longer then the word on each side! mmm, not sure what’s going on here!!
      • 20413
      • 2,877 Posts
      Did you restore your document.parser? Was the reason you hacked it, because you got an error message?
      What if you use this code only
      $output = &$modx->documentOutput;
      $output = str_replace(" maddona ", ' <a href="maddona.html">maddona</a> ', $output);
      return $output;


      Maybe another plugin is conflicting?

        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 3071
        • 99 Posts
        If I just use that I get this:

        Fatal error: Call to undefined function str_replace_once() in /home/quirkybe/public_html/manager/includes/document.parser.class.inc.php(745) : eval()'d code on line 4

        embarrassed
          • 3071
          • 99 Posts
          So when I get it to work it renders the code like this:

          <a href="madonnna.html"> <a href="madonnna.html"> <a href="madonnna.html"> <a href="madonnna.html"> <a href="madonnna.html"> <a href="madonnna.html"> <a href="madonnna.html"> <a href="madonnna.html"> <a href="madonnna.html"> madonnna </a> </a> </a> </a> </a> </a> </a> </a> </a>


          Strange, have you checked your page code and are not getting the same?
            • 3071
            • 99 Posts
            Used the code you sent and it now doesn’t just link the first instance, links them all BUT doesn’t put more than one href link in per keyword. Confused, need a PHP Don to help!!!

             if (!function_exists('str_replace_once')) {
                function str_replace_once($needle , $replace , $haystack){
                    // Looks for the first occurence of $needle in $haystack
                    // and replaces it with $replace.
                    $pos = strpos($haystack, $needle);
                    if ($pos === false) {
                        // Nothing found
                        return $haystack;
                    }
                    return substr_replace($haystack, $replace, $pos, strlen($needle));
                }
            }
            
            $output = &$modx->documentOutput;
            $output = str_replace_once(" consolidation ", ' <a href="consolidation.html">consolidation</a> ', $output); //notice str_replace_once
            $output = str_replace_once(" RedBull ", ' <a href="redbull.html">RedBull</a> ', $output); //instead of str_replace
            return $output;
              • 6511
              • 60 Posts
              danny_kay1710 Reply #26, 16 years ago
              I have the same problem on Revo, When I enable this plugin I get no output at all.

              I changed the code around a little and got multiple <b> tags (I am replacing the hyperlink tags with bold tags) similar to benchesters.

              With this:

              <?php
                $output = str_replace(' machinery safety', ' <b>machinery safety</b>', $modx->documentOutput);
                $modx->documentOutput = $output;  
              ?>​


              Everything works as I wanted so modifying it to
              if (!function_exists('str_replace_once')) {
                  function str_replace_once($needle , $replace , $haystack){
                      // Looks for the first occurence of $needle in $haystack
                      // and replaces it with $replace.
                      $pos = strpos($haystack, $needle);
                      if ($pos === false) {
                          // Nothing found
                          return $haystack;
                      }
                      return substr_replace($haystack, $replace, $pos, strlen($needle));
                  }
              }
              
                $output = str_replace_once(' machinery safety', ' <a href="mahcinery-safety">machinery safety</a>', $modx->documentOutput);
                $modx->documentOutput = $output;  
              


                • 3071
                • 99 Posts
                I am still messing with this now...I thought this would be relatively simple, but seems I was wrong, once again!!
                  • 6511
                  • 60 Posts
                  danny_kay1710 Reply #28, 16 years ago
                  See my edit to previous post, editing because I didn’t want to double post but you beat me to it!!!

                  Here it is again:



                  With this:

                  <?php
                    $output = str_replace(' machinery safety', ' <b>machinery safety</b>', $modx->documentOutput);
                    $modx->documentOutput = $output;  
                  ?>​


                  Everything works as I wanted so modifying it to
                  <?php
                  if (!function_exists('str_replace_once')) {
                      function str_replace_once($needle , $replace , $haystack){
                          // Looks for the first occurence of $needle in $haystack
                          // and replaces it with $replace.
                          $pos = strpos($haystack, $needle);
                          if ($pos === false) {
                              // Nothing found
                              return $haystack;
                          }
                          return substr_replace($haystack, $replace, $pos, strlen($needle));
                      }
                  }
                  
                  $output = str_replace_once(' machinery safety', ' <a href="mahcinery-safety">machinery safety</a>', $modx->documentOutput);
                  $modx->documentOutput = $output;  
                  ?>
                  

                    • 3071
                    • 99 Posts
                    That code works BUT when I check the webpage code I see this:

                    but its how we deal with <a href="debt"> <a href="debt"> <a href="debt"> <a href="debt"> <a href="debt"> <a href="debt"> <a href="debt"> <a href="debt"> <a href="debt"> debt </a></a></a></a></a></a></a></a></a>that really matters.


                    Does anyone have any idea whatsoever what is causing the 9 href links here??
                      • 6511
                      • 60 Posts
                      danny_kay1710 Reply #30, 16 years ago
                      Clear your sites cache and try again.

                      Make sure that you have a space at the front of the search term but not at the end. (This way it allows for punctuation such as commas in general text)

                      Hope this helps