Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Php str_replace

  1. #1
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post

    Php str_replace

    Hi there,

    I have a comments system, where people can post comments. I have disabled html and the <> tags, so i am making my own bord code. At the moment, people can add images by putting in [img]image url here[/img]. This is the code i have that lets people do this...

    PHP Code:
    $imgtag = array("[img]""[/img]");
    $replacetag = array("<img src='","' id='usr'>");
    $newcomment str_replace($imgtag$replacetag$row2[comments]);

    $postedcomment wordwrap($newcomment,83" "1);

    echo
    "$postedcomment"
    My question is, i want to add in another tag so that people can make their text bold by putting........[1b]This text will be bold without the 1 in the tag[/1b] - (I have put the 1 in the b tag because if i dont, then this forum board code will acctually make the text bold because that is the tag that they use).

    This is the code i have so far...

    PHP Code:
    $boldtag = array("[b]""[/b]");
    $replacetagbold = array("<b>","</b>");
    $newcomment2 str_replace($boldtag$replacetagbold$row2[comments]); 
    Now, i have tried so many ways to link it up with the other code, like merge them together, but everything i have tried fails. How can i merge the bold replace with the img replace so that people can use both [img] and [b] tags???

    Last edited by Andy92; 02-25-2007 at 09:02 PM.

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Use regular expressions. Search the forums, there have been lots of posts regarding this exact topic.
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

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