2 Replies Latest reply on Dec 29, 2009 9:11 AM by Joseph07888

    Limit wording & remove HTML tags - HELP

    Joseph07888 Level 1

      Hi All,

       

      Almost happy new year!

       

      If someone could give me a hand with this i would be very grateful.

       

      I am trying to create a small simple script but seem to have lost the plot as don't know whats wrong.

       

      It needs to remove all the HTML from a recordset result (e.g. wording) and limit the display text to 300 charaters.

       

      Script below between ****************************** / ***************************************

       

       

      *******************************************************

       

      combined

      <?php
      $position=300; // Define how many character you want to display.
      $message=$row_rsCMSevents['WordingEvent'];
      echo strip_tags($message);
      echo "\n";
      $post = substr($message, 0, $position);
      echo strip_tags($message, '<p><br />');// Allow <p> and <br />

      ?>

       

      just text limited

      <?php

      $position=300; // Define how many character you want to display.

      $message=$row_rsCMSevents['WordingEvent'];
      $post = substr($message, 0, $position);

      echo $post;
      echo "";

      ?>

       

       

      just strip tags

       

       

      <?php
      $text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
      echo strip_tags($text);
      echo "\n";

      // Allow <p> and <a>
      echo strip_tags($text, '<p><a>');
      ?>

      *******************************************************

       

      I know not ADDT fully but you guys n girls are the stars i count on when in a fix.

       

      Cheers,

      Joe

        • 1. Re: Limit wording & remove HTML tags - HELP
          Günter Schenk Level 4

          Hi Joe,

           

          Joseph07888 wrote:

           

          combined

          <?php
          $position=300; // Define how many character you want to display.
          $message=$row_rsCMSevents['WordingEvent'];
          echo strip_tags($message);
          echo "\n";
          $post = substr($message, 0, $position);
          echo strip_tags($message, '<p><br />');// Allow <p> and <br />

          ?>

           

           

          It looks like the declared variable $post (which is supposed to truncate $message according to the $position value) is actually not used -- that said, please try with:

           

          echo strip_tags($post, '<p><br />');

           

          ..which definitely works for me BTW ;-)

           

          Cheers,

          Günter

          • 2. Re: Limit wording & remove HTML tags - HELP
            Joseph07888 Level 1

            Hi Gunter,

             

            Once again your skills are exceptional!

             

            I the final result is

             

             

            <?php
            $position=300; // Define how many character you want to display.
            $message=$row_rsCMSevents['WordingEvent'];
            echo "\n";
            $post = substr($message, 0, $position);
            echo strip_tags($post, '');
            ?>

             

            choosing not to allow any html at all and limit it down to a nice little wording description.

             

            Cheers,

            Joe

            P.s. This beer collection for you is growing and I will make the trip over one day as the German Market in Leeds (UK) was a hoot! The larger was great!

             

            Have a great new year and talk soon!