SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Str_replace not working!

    PHP Code:
    $viewpost str_replace(":)""<img src=\"images/emotions/smile.gif\" alt=\"Smile\" />"$reply[post]); 
    $viewpost str_replace(":(""<img src=\"images/emotions/frown.gif\" alt=\"Sad\" />"$reply[post]); 
    $viewpost str_replace(":roll:""<img src=\"images/emotions/roll.gif\" alt=\"Sarcasm\" />"$reply[post]); 
    $viewpost str_replace(":D""<img src=\"images/emotions/grin.gif\" alt=\"Huge Grin\" />"$reply[post]); 
    $viewpost str_replace(";)""<img src=\"images/emotions/wink.gif\" alt=\"Wink\" />"$reply[post]); 
    $viewpost str_replace(":p""<img src=\"images/emotions/tongue.gif\" alt=\"Laugh\" />"$reply[post]); 

    $viewpost str_replace("[B]""<b>"$reply[post]); 
    $viewpost str_replace("[/B]""</b>"$reply[post]); 

    $viewpost str_replace("[I]""<i>"$reply[post]); 
    $viewpost str_replace("[/I]""</i>"$reply[post]); 

    $viewpost str_replace("[U]""<u>"$reply[post]); 
    $viewpost str_replace("[/U]""</u>"$reply[post]); 

    $viewpost str_replace("[QUOTE]""<table border=\"1\" cellspacing=\"0\" width=\"90%\"><tr border=\"0\" width=\"90%\"><td border=\"0\" width=\"90%\"><font size=\"-2\"><B>Quote:</b></font><font size=\"-1\">"$reply[post]); 
    $viewpost str_replace("[/QUOTE]""</font></td></tr></table>"$reply[post]); 

    $viewpost str_replace("[CODE]""<table border=\"1\" cellspacing=\"0\" width=\"90%\"><tr border=\"0\" width=\"90%\><td border=\"0\" width=\"90%\"><font size=\"-2\"><B>Code:</b></font><font size=\"-1\">"$reply[post]); 
    $viewpost str_replace("[/CODE]""</font></td></tr></table>"$reply[post]); 

    $viewpost str_replace("[IMG]""<img src=\""$reply[post]); 
    $viewpost str_replace("[/IMG]""\" border=\"0\">"$reply[post]); 

    $viewpost str_replace("[URL=""<a href=\""$reply[post]); 
    $viewpost str_replace("]""\">"$reply[post]); 
    $viewpost str_replace("[/URL]""</a>"$reply[post]); 

    $viewpost str_replace("[EMAIL=""<a href=\""$reply[post]); 
    $viewpost str_replace("]""\">"$reply[post]); 
    $viewpost str_replace("[/EMAIL]""</a>"$reply[post]); 




    print 
    $viewpost

    I have all that for my BB code, and smilies.

    Some of the smilies work, others don't, and none of the BB code works!

    Any ideas?

    Thanks,
    ~someonewhois

  2. #2
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe code will work... :S


    Code:
    $viewpost = str_replace(":)", "<img src=\"images/emotions/smile.gif\" alt=\"Smile\" />", $reply[post]); 
    $viewpost = str_replace(":(", "<img src=\"images/emotions/frown.gif\" alt=\"Sad\" />", $reply[post]); 
    $viewpost = str_replace(":roll:", "<img src=\"images/emotions/roll.gif\" alt=\"Sarcasm\" />", $reply[post]); 
    $viewpost = str_replace(":D", "<img src=\"images/emotions/grin.gif\" alt=\"Huge Grin\" />", $reply[post]); 
    $viewpost = str_replace(";)", "<img src=\"images/emotions/wink.gif\" alt=\"Wink\" />", $reply[post]); 
    $viewpost = str_replace(":p", "<img src=\"images/emotions/tongue.gif\" alt=\"Laugh\" />", $reply[post]); 
    
    $viewpost = str_replace("", "<b \>", $reply[post]); 
    $viewpost = str_replace("", "</b>", $reply[post]); 
    
    $viewpost = str_replace("", "<i>", $reply[post]); 
    $viewpost = str_replace("", "</i>", $reply[post]); 
    
    $viewpost = str_replace("", "<u>", $reply[post]); 
    $viewpost = str_replace("", "</u>", $reply[post]); 
    
    $viewpost = str_replace("
    ", "<table border=\"1\" cellspacing=\"0\" width=\"90%\" /><tr border=\"0\" width=\"90%\" /><td border=\"0\" width=\"90%\" /><font size=\"-2\" /><B>Quote:</b></font><font size=\"-1\" />", $reply[post]); $viewpost = str_replace("
    ", "</font></td></tr></table>", $reply[post]); $viewpost = str_replace("
    Code:
    ", "<table border=\"1\" cellspacing=\"0\" width=\"90%\" /><tr border=\"0\" width=\"90%\" /><td border=\"0\" width=\"90%\" /><font size=\"-2\" /><B>Code:</b></font><font size=\"-1\" />", $reply[post]); 
    $viewpost = str_replace("
    ", "</font></td></tr></table>", $reply[post]); $viewpost = str_replace("[IMG]", "<img src=\"", $reply[post]); $viewpost = str_replace("[/IMG]", "\" border=\"0\" />", $reply[post]); $viewpost = str_replace("", "\" />", $reply[post]); $viewpost = str_replace("", "</a>", $reply[post]); $viewpost = str_replace("", "\" />", $reply[post]); $viewpost = str_replace("", "</a>", $reply[post]);

    I dont' get it, if I comment all but the bold ones, the one for </b>, but that's it...

    Is it becuase I can't have more than one for each variable (i.e. $viewpost)?

    If so, how can I fix it?

  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would I do those with arrays?

    That might be what I need...

  4. #4
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    without looking to hard at your code, i think the problem is that you keep re-assigning $viewpost to a str_replaced version of $reply[post]. i think it's worth doing the following:
    PHP Code:
    $viewpost $reply[post
    at the beginning, and then changing all your str_replaces to something like this
    PHP Code:
    $viewpost str_replace("\[i\]""<i>"$viewpost); // $viewpost at the end, and NOT $reply[post] 
    give it a whirl, you never know...
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  5. #5
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    additionally

    for the more complicated ones, like the [EMAIL=foo@bar.com] ones, it's not really possible to use your format or first replacing [EMAIL= and then later the ]. i suggest regular expressions for these more elaborate ones (elaborate meaning not just a simple tag like \[b\] or something.

    e.g.
    PHP Code:
    $viewpost=eregi_replace("\\[email=([^]]*)\\]","<a href=\\"mailto:\\\\1\">\\\\1</a>",$viewpost); 
    (i hope this is correct...just whizzed it up without double-checking)
    Last edited by redux; Apr 21, 2002 at 05:13.
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried teh first one first, I dont' understand the email one.

    PHP Code:
    $viewposts $reply['post'];

    $viewpost str_replace(":)""<img src=\"images/emotions/smile.gif\" alt=\"Smile\" />"$viewpost
    $viewpost str_replace(":(""<img src=\"images/emotions/frown.gif\" alt=\"Sad\" />"$viewpost)
    $viewpost str_replace(":roll:""<img src=\"images/emotions/roll.gif\" alt=\"Sarcasm\" />"$viewpost)
    $viewpost str_replace(":D""<img src=\"images/emotions/grin.gif\" alt=\"Huge Grin\" />"$viewpost)
    $viewpost str_replace(";)""<img src=\"images/emotions/wink.gif\" alt=\"Wink\" />"$viewpost)
    $viewpost str_replace(":p""<img src=\"images/emotions/tongue.gif\" alt=\"Laugh\" />"$viewpost)

    $viewpost str_replace("[B]""<b>"$viewpost
    $viewpost str_replace("[/B]""</b>"$viewpost


    $viewpost str_replace("[I]""<i>"$viewpost); 
    $viewpost str_replace("[/I]""</i>"$viewpost); 

    $viewpost str_replace("[U]""<u>"$viewpost); 
    $viewpost str_replace("[/U]""</u>"$viewpost); 

    $viewpost str_replace("[QUOTE]""<table border=\"1\" cellspacing=\"0\" width=\"90%\" /><tr border=\"0\" width=\"90%\" /><td border=\"0\" width=\"90%\" /><font size=\"-2\" /><B>Quote:</b></font><font size=\"-1\" />"$viewpost); 
    $viewpost str_replace("[/QUOTE]""</font></td></tr></table>"$viewpost); 

    $viewpost str_replace("[CODE]""<table border=\"1\" cellspacing=\"0\" width=\"90%\" /><tr border=\"0\" width=\"90%\" /><td border=\"0\" width=\"90%\" /><font size=\"-2\" /><B>Code:</b></font><font size=\"-1\" />"$viewpost); 
    $viewpost str_replace("[/CODE]""</font></td></tr></table>"$viewpost); 

    $viewpost str_replace("[IMG]""<img src=\""$viewpost); 
    $viewpost str_replace("[/IMG]""\" border=\"0\" />"$viewpost); 

    $viewpost str_replace("[URL=""<a href=\""$viewpost); 
    $viewpost str_replace("]""\" />"$viewpost); 
    $viewpost str_replace("[/URL]""</a>"$viewpost); 

    $viewpost str_replace("[EMAIL=""<a href=\""$viewpost); 
    $viewpost str_replace("]""\" />"$viewpost); 
    $viewpost str_replace("[/EMAIL]""</a>"$viewpost); 

    echo 
    "$viewpost"

    That gives an error on the second one.

    This line:
    PHP Code:
    $viewpost str_replace(":(""<img src=\"images/emotions/frown.gif\" alt=\"Sad\" />"$viewpost
    Why is this?

    Thanks for your help,
    ~someonewhois

  7. #7
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wish you could turn OFF BB code for posts...

    The error is here, I forgot to disable smillies;

    PHP Code:
    $viewpost str_replace(":(""<img src=\"images/emotions/frown.gif\" alt=\"Sad\" />"$viewpost

  8. #8
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think you're missing a couple of ";" at the end of your lines...
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  9. #9
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OOPS!

    That explains it!

  10. #10
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    after all that it was some ; that I was mising!

    Thank you everybody!

  11. #11
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    everybody ? i am only one
    no worries...sometimes it's those pesky small things that we all overlook that can mess up some fantastically complex programme logic...
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  12. #12
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh, you are the only one!


    Thank you redux!



Bookmarks

Posting Permissions

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