ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

str_replace problem

March 17, 2010 4:49pm

Subscribe [2]
  • #1 / Mar 17, 2010 4:49pm

    j0han

    20 posts

    Hi all,
    I’m having this weird problem with a real simple plugin I’m trying to write. For a project running on 1.6.8 I need to replace hr tags by hmtl a little more fancy.
    Sounds simple, but for some strange reason, this won’t work:

    $newstr = str_replace('<hr >', '<div class="hr"><hr ></div>', $data);

    i can get it to work if i change it to

    $newstr = str_replace('<hr ', '<div class="hr"><hr ></div>', $data);

    but that’s not what i need.
    For some strange reason EE doesn’t like the last

    >

    and I can’t figure out why.
    Any ideas?

  • #2 / Mar 17, 2010 4:54pm

    Focus Lab Dev Team

    1129 posts

    That’s odd. Can you share a larger portion of the plugin? At face value I’m not sure what would cause this.

  • #3 / Mar 17, 2010 5:04pm

    j0han

    20 posts

    <?php
    
        $plugin_info       = array(
       'pi_name'        => 'Style HR',
       'pi_version'     => '0.1',
       'pi_author'      => 'J0han',
       'pi_author_url'  => 'http://j0han.com',
       'pi_description' => 'Fancy horizontal rules',
       'pi_usage'       => Style_hr::usage()
       );
    
    class Style_hr {
       
       function Style_hr() {
    
            global $TMPL;
            $data = $TMPL->tagdata;  
    
            $newstr = str_replace('<hr >', '<div class="hr"><hr ></div>', $data);        
            
            $this->return_data = $newstr;
       }
    
    
      // ----------------------------------------
      //  Plugin Usage
      // ----------------------------------------
    
    
       function usage()
       {
       ob_start(); 
       ?>
    
       {exp:style_hr}html goes here{/exp:style_hr}
    
       <?php
       $buffer = ob_get_contents();
    
       ob_end_clean(); 
    
       return $buffer;
       }
    }
    
    ?>
  • #4 / Mar 17, 2010 5:13pm

    Focus Lab Dev Team

    1129 posts

    Ah silly me. EE converts your html entities so you need to undo that. globalize the REGX class as well and change line 17 from this

    $data = $TMPL->tagdata;

    to this

    $data = $REGX->unhtmlentities($TMPL->tagdata);
  • #5 / Mar 17, 2010 7:03pm

    j0han

    20 posts

    does the trick!
    Thanks alot Erik!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases