str_replace

Discussion in 'PHP' started by Silver89, Jul 28, 2009.

  1. #1
    Does anyone have a custom function to strip all tags apart from:

    
    <br />
    <p></p>
    <strong></strong>
    <b></b>
    
    Code (markup):
    Thanks +
     
    Silver89, Jul 28, 2009 IP
  2. vetrivel

    vetrivel Peon

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    http://forums.digitalpoint.com/showthread.php?t=1421903

    function get_string_between($string, $start, $end){
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0) return "";
    $ini += strlen($start);
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len);
    }

    $str = "hell my name is [andrew]";
    echo get_string_between($str, "[", "]");



     
    vetrivel, Jul 28, 2009 IP
  3. Agent_Smith

    Agent_Smith Well-Known Member

    Messages:
    890
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    145
    #3
    Agent_Smith, Jul 28, 2009 IP
  4. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #4
    I'm also trying to strip the following javascript with the following, but it only removes the tags and not the content?

    
    <?=str_replace('@<script[^>]*?>.*?</script>@si','',$desc);?>
    
    PHP:
    
    <SCRIPT LANGUAGE=\'JavaScript\' type=\'text/javascript\'>
    var itemNumber = window.ItemID ? window.ItemID : -1; 
    function passpara(){return \'&id=755539&itembgcolor=0xFFFFFF&bordercolor=0x000000&storewindowbgcolor=
    0xb8d6b6&toptextcolor=0xFFFFFF&bottomtextcolor=0xFFFFFF&stripcolor=0x516bc6&auctionclosemessagecolor
    =0xff0000&emptyboxmessagecolor=0xFFFFFF&buttovercolor=0x660000&buttoutcolor=0x00000AA&searchtitleco
    lor=0xFFFFFF&searchbuttbgcolor=0xc0c0c0&searchbutttextcolor=0x000000&searchbuttbordercolor=0x000000&
    itemhighlightcolor=0xfff000&navbuttonactivecolor=0x4bc1ee&navbuttonoutlinecolor=0xff9900&navbuttoninacti
    vebgcolor=0x000000&siteid=0&cat=115280&item=\' + itemNumber + \'&baseurl=\'+escape(location.href.substr
    ing(0, location.href.lastIndexOf(\'/\') + 1));}  
    </script>
    
    
    Code (markup):
     
    Silver89, Jul 28, 2009 IP
  5. Martinoes

    Martinoes Peon

    Messages:
    110
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try this code:

    <?=str_replace('@<script[^>]*?>([^<]*?)</script>@si','',$desc);?>

    <script LANGUAGE=\'JavaScript\' type=\'text/javascript\'>
    var itemNumber = window.ItemID ? window.ItemID : -1; 
    function passpara(){return \'&id=755539&itembgcolor=0xFFFFFF&bordercolor=0x000000&storewindowbgcolor=
    0xb8d6b6&toptextcolor=0xFFFFFF&bottomtextcolor=0xFFFFFF&stripcolor=0x516bc6&auctionclosemessagecolor
    =0xff0000&emptyboxmessagecolor=0xFFFFFF&buttovercolor=0x660000&buttoutcolor=0x00000AA&searchtitleco
    lor=0xFFFFFF&searchbuttbgcolor=0xc0c0c0&searchbutttextcolor=0x000000&searchbuttbordercolor=0x000000&
    itemhighlightcolor=0xfff000&navbuttonactivecolor=0x4bc1ee&navbuttonoutlinecolor=0xff9900&navbuttoninacti
    vebgcolor=0x000000&siteid=0&cat=115280&item=\' + itemNumber + \'&baseurl=\'+escape(location.href.substr
    ing(0, location.href.lastIndexOf(\'/\') + 1));}  
    </script>
    PHP:
     
    Martinoes, Jul 29, 2009 IP