Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default str_replace quirk

    Why does the following not replace the ":)"?
    str_replace(":)", "&nbsp;<img
    src=http://www.com.com/forum/emoticons/smiley.gif>&nbsp;", $_POST['Tip']);

    But, the following does replace the ":("?

    str_replace(":(", "&nbsp;<img
    src=http://www.com.com/forum/emoticons/crying.gif>&nbsp;", $_POST['Tip']);


    --
    --------
    Jon Rosenberg


    Jon Guest

  2. Similar Questions and Discussions

    1. DataGrid/XMLConnector quirk?
      I am using the Macromedia tutorial on Data Integration to populate a DataGrid from an XMLConnector: ...
    2. Library Items Quirk
      Every time I insert a library item I've created it inserts a </table> and then generates an open table. How do I make it stop? I went in and deleted...
    3. ID CS: Anyone Else See This ID CS to Acrobat 6 Pro Quirk?
      I can't tell if this is an Acrobat6 Pro, ID CS problem, a little of both or something I'm doing wrong. On a master page, place a black box or line...
    4. Save As PDF Quirk
      Thanks to the expertise and good graces of John Kallios, we seem to have found an oddity (dare I say a bug?) in the Save As PDF command. This will...
    5. Keyboard / Mouse quirk....
      I've defined a Key object and within its onPress action I set a variable userKeyUp to false. In the Key's onRelease action I set userKeyUp back to...
  3. #2

    Default Re: str_replace quirk

    Forgot to add....I am running PHP 4.3.0.


    "Jon" <ruffles74@hotmail.com> wrote in message
    news:vk46o0e5fg9f18@corp.supernews.com...
    > Why does the following not replace the ":)"?
    > str_replace(":)", "&nbsp;<img
    > src=http://www.com.com/forum/emoticons/smiley.gif>&nbsp;", $_POST['Tip']);
    >
    > But, the following does replace the ":("?
    >
    > str_replace(":(", "&nbsp;<img
    > src=http://www.com.com/forum/emoticons/crying.gif>&nbsp;", $_POST['Tip']);
    >
    >
    > --
    > --------
    > Jon Rosenberg
    >
    >

    Jon Guest

  4. #3

    Default Re: str_replace quirk

    Duh, stupid me. Thanks for pointing that out to me.


    "Damian Brown" <damian@phpexpert.org> wrote in message
    news:bht7pe$pqp$1@titan.btinternet.com...
    > jon,
    >
    > it is because of the closed bracket
    > the closed bracket in str_replace(":)"
    > tells the interpreter that that is the end of the statement
    > it works with :( because it does not take it as the end of the statement
    >
    > i'm not sure, but you may have to put a backslash before it i.e. \)
    >
    > Regards,
    > Damian
    > [url]www.phpexpert.org/chat/[/url]
    > UK FREEphone 0800 019 0924
    >
    >
    > "Jon" <ruffles74@hotmail.com> wrote in message
    > news:vk46o0e5fg9f18@corp.supernews.com...
    > > Why does the following not replace the ":)"?
    > > str_replace(":)", "&nbsp;<img
    > > src=http://www.com.com/forum/emoticons/smiley.gif>&nbsp;",
    $_POST['Tip']);
    > >
    > > But, the following does replace the ":("?
    > >
    > > str_replace(":(", "&nbsp;<img
    > > src=http://www.com.com/forum/emoticons/crying.gif>&nbsp;",
    $_POST['Tip']);
    > >
    > >
    > > --
    > > --------
    > > Jon Rosenberg
    > >
    > >
    >
    >

    Jon Guest

  5. #4

    Default Re: str_replace quirk

    it was good to be of assistance
    you can reach me on CHAT
    at [url]www.phpexpert.org/chat/[/url]
    if you have any further problems

    Regards,
    Damian
    [url]www.phpexpert.org[/url]
    UK FREEphone 0800 019 0924

    "Jon" <ruffles74@hotmail.com> wrote in message
    news:vk49u8ncaeneea@corp.supernews.com...
    > Duh, stupid me. Thanks for pointing that out to me.
    >
    >
    > "Damian Brown" <damian@phpexpert.org> wrote in message
    > news:bht7pe$pqp$1@titan.btinternet.com...
    > > jon,
    > >
    > > it is because of the closed bracket
    > > the closed bracket in str_replace(":)"
    > > tells the interpreter that that is the end of the statement
    > > it works with :( because it does not take it as the end of the statement
    > >
    > > i'm not sure, but you may have to put a backslash before it i.e. \)
    > >
    > > Regards,
    > > Damian
    > > [url]www.phpexpert.org/chat/[/url]
    > > UK FREEphone 0800 019 0924
    > >
    > >
    > > "Jon" <ruffles74@hotmail.com> wrote in message
    > > news:vk46o0e5fg9f18@corp.supernews.com...
    > > > Why does the following not replace the ":)"?
    > > > str_replace(":)", "&nbsp;<img
    > > > src=http://www.com.com/forum/emoticons/smiley.gif>&nbsp;",
    > $_POST['Tip']);
    > > >
    > > > But, the following does replace the ":("?
    > > >
    > > > str_replace(":(", "&nbsp;<img
    > > > src=http://www.com.com/forum/emoticons/crying.gif>&nbsp;",
    > $_POST['Tip']);
    > > >
    > > >
    > > > --
    > > > --------
    > > > Jon Rosenberg
    > > >
    > > >
    > >
    > >
    >
    >

    Damian Brown Guest

  6. #5

    Default Re: str_replace quirk

    You're right...and I solved it by not bothering with str_replace and just
    made a regex using preg_replace. I'm not sure exactly what was going on
    with str_replace...but, after playing with it more, it does not seem to be
    the ).

    Here's the simple regex I used:
    $post = preg_replace("/\:\)/", "&nbsp;<img
    src=http://www.com.com/forum/emoticons/smiley.gif>&nbsp;", $post);

    $post = preg_replace("/\;\)/", "&nbsp;<img
    src=http://www.com.com/forum/emoticons/wink.gif>&nbsp;", $post);

    $post = preg_replace("/\:\(/", "&nbsp;<img
    src=http://www.com.com/forum/emoticons/crying.gif>&nbsp;", $post);


    "Jochen Buennagel" <zang@buennagel.com> wrote in message
    news:bhtc5o$pn0$05$1@news.t-online.com...
    > Damian Brown wrote:
    >
    > > it is because of the closed bracket
    > > the closed bracket in str_replace(":)"
    > > tells the interpreter that that is the end of the statement
    > > it works with :( because it does not take it as the end of the statement
    >
    > Sorry, but the closing bracket has nothing to do with it because it is
    > enclosed in "", thus it is part of the string.
    >
    > As an aside: the code works nicely for me as it is. (Running PHP 4.3.2)
    >
    > Jochen
    >
    > --
    > /**
    > * @author Jochen Buennagel <zang at buennagel dot com>
    > * @see [url]http://www.sourceforge.net/projects/zang[/url]
    > */
    >

    Jon Guest

  7. #6

    Default Re: str_replace quirk

    i'm glad you got it going
    i'm no expert, i'm just learning

    "Jon" <ruffles74@hotmail.com> wrote in message
    news:vk4dfpgrtecae7@corp.supernews.com...
    > You're right...and I solved it by not bothering with str_replace and just
    > made a regex using preg_replace. I'm not sure exactly what was going on
    > with str_replace...but, after playing with it more, it does not seem to be
    > the ).
    >
    > Here's the simple regex I used:
    > $post = preg_replace("/\:\)/", "&nbsp;<img
    > src=http://www.com.com/forum/emoticons/smiley.gif>&nbsp;", $post);
    >
    > $post = preg_replace("/\;\)/", "&nbsp;<img
    > src=http://www.com.com/forum/emoticons/wink.gif>&nbsp;", $post);
    >
    > $post = preg_replace("/\:\(/", "&nbsp;<img
    > src=http://www.com.com/forum/emoticons/crying.gif>&nbsp;", $post);
    >
    >
    > "Jochen Buennagel" <zang@buennagel.com> wrote in message
    > news:bhtc5o$pn0$05$1@news.t-online.com...
    > > Damian Brown wrote:
    > >
    > > > it is because of the closed bracket
    > > > the closed bracket in str_replace(":)"
    > > > tells the interpreter that that is the end of the statement
    > > > it works with :( because it does not take it as the end of the
    statement
    > >
    > > Sorry, but the closing bracket has nothing to do with it because it is
    > > enclosed in "", thus it is part of the string.
    > >
    > > As an aside: the code works nicely for me as it is. (Running PHP 4.3.2)
    > >
    > > Jochen
    > >
    > > --
    > > /**
    > > * @author Jochen Buennagel <zang at buennagel dot com>
    > > * @see [url]http://www.sourceforge.net/projects/zang[/url]
    > > */
    > >
    >
    >

    Damian Brown Guest

  8. #7

    Default Re: str_replace quirk

    Damian Brown wrote:
    > i'm just learning
    We all are. The minute you think you have nothing left to learn about a
    language is the exact time your programming career starts to end.

    --
    Justin Koivisto - [email]spam@koivi.com[/email]
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

    Justin Koivisto Guest

  9. #8

    Default Re: str_replace quirk

    Jon wrote:
    > Why does the following not replace the ":)"?
    > str_replace(":)", "&nbsp;<img
    > src=http://www.com.com/forum/emoticons/smiley.gif>&nbsp;", $_POST['Tip']);
    >
    > But, the following does replace the ":("?
    >
    > str_replace(":(", "&nbsp;<img
    > src=http://www.com.com/forum/emoticons/crying.gif>&nbsp;", $_POST['Tip']);
    >
    >
    Try using single quotes instead - if you're not interpolating a variable,
    it's MUCH better to use ' instead of ", since there's no need for the parser
    to check the contents of the string for variable names.

    The other point, is that str_replace doesn't change the string directly - it
    returns the result of the replace, so you'd need to do

    $_POST['Tip'] = str_replace(':)', '&nbsp;<img src="http://www.com.com/icons/crying.gif" alt="Crying Smiley" />&nbsp;', $_POST['Tip']);

    or something similar - remember
    1 - attribute values should be quoted (src="this.gif")
    2 - img tags should be closed (<img src=..... />)
    3 - add an alt attribute, so that the img means something even if people don't/can't
    display images; and so that this will help you towards writing valid code, depending
    on your variant of html/xhtml

    Matt

    --
    Matt Mitchell - AskMeNoQuestions
    Dynamic Website Development and Marketing
    matty Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139