Results 1 to 2 of 2

Thread: Having trouble with str_replace

  1. #1

    Thread Starter
    Member
    Join Date
    May 2004
    Location
    Where i am
    Posts
    38

    Having trouble with str_replace

    function prepared($post){

    $bbopen = array("[!b]", "[!i]", "[!u]", "[!hr]", "[!quote]", "[!code]";
    $bbclose = array("[!/b]", "[!/i]", "[!/u]", "[!/quote]", "[!/code]");

    $mlopen = array("<b>", "<i>", "<u>", "<hr/>", '<b>Quote:</b><p style="border:solid; border-color:#0000FF">', '<b>Code:</b><p style="border:solid; border-color:#ABABAB">');
    $mlclose = array("</b>", "</i>", "</u>", "</p>", "</p>"); # open tags
    str_replace($bbopen, $mlopen, $post);

    # close tags
    str_replace($bbclose, $mlclose, $post);

    str_replace("\n", "<br>", $post);
    str_replace("\r", "<br>", $post);
    str_replace("<", "&lt;", $post);
    str_replace(">", "&gt;", $post);


    return $post;
    }
    I wrote my own forum for something to do to pass the time but I can't get the above to do anything, meaning people could use html and javascript potentially if they realised. But it doesn't seem to change the string I pass to it. Any help would be appreciated.

    Note the ! was to stop this forums bb-code working on them.

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Having trouble with str_replace

    you need to set the replaced text to a varible, not just call the function
    PHP Code:
    $post str_replace(">""&gt;"$post); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width