Could somebody help me come up with some code that scans a given string for uppercase BBCode, and converts it to lowercase?

i.e.

$data="[SOMETHING]I am a Banana![SOMETHING]"
taglower($data)="[something]I am a Banana![/something]"

or

$data="[GLECK=48]Mosquitoes make good muffins![/GLECK]"
taglower($data)="[gleck=48]Mosquitoes make good muffins![/gleck]"

    See if this does the trick:

    $data = preg_replace('/\[([^\]]+)\]/e', '"[".strtolower(\\1)."]"', $data);
    
      <?php
      
      $data = "[BEE]eee with me[/BEE]";
      
      function taglower($data){
      $data = preg_replace('/\[([^\]]+)\]/e', '"[".strtolower(\\1)."]"', $data);
      return $data;
      }
      
      echo taglower($data);
      
      ?>

      Parse error: syntax error, unexpected '/', expecting ')' in /nfsn/content/pulsoid/public/test/bb/taglower.php(6) : regexp code on line 1

      Fatal error: preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Failed evaluating code: &quot;[&quot;.strtolower(/BEE).&quot;]&quot; in /nfsn/content/pulsoid/public/test/bb/taglower.php on line 6

        I would say...

        $data = preg_replace('/\[([^\]]+)\]/e', '"[".strtolower("\\1")."]"', $data);
        

          Thank you much. Works flawlessly (so far).

            suntra wrote:

            I would say...

            $data = preg_replace('/\[([^\]]+)\]/e', '"[".strtolower("\\1")."]"', $data);
            

            Thanks, not the first time I forgot the quotes in that situation. :rolleyes:

              Write a Reply...