Ask a Question related to PHP Development, Design and Development.
-
Jon #1
str_replace quirk
Why does the following not replace the ":)"?
str_replace(":)", " <img
src=http://www.com.com/forum/emoticons/smiley.gif> ", $_POST['Tip']);
But, the following does replace the ":("?
str_replace(":(", " <img
src=http://www.com.com/forum/emoticons/crying.gif> ", $_POST['Tip']);
--
--------
Jon Rosenberg
Jon Guest
-
DataGrid/XMLConnector quirk?
I am using the Macromedia tutorial on Data Integration to populate a DataGrid from an XMLConnector: ... -
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... -
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... -
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... -
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... -
Jon #2
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(":)", " <img
> src=http://www.com.com/forum/emoticons/smiley.gif> ", $_POST['Tip']);
>
> But, the following does replace the ":("?
>
> str_replace(":(", " <img
> src=http://www.com.com/forum/emoticons/crying.gif> ", $_POST['Tip']);
>
>
> --
> --------
> Jon Rosenberg
>
>
Jon Guest
-
Jon #3
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...$_POST['Tip']);> 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(":)", " <img
> > src=http://www.com.com/forum/emoticons/smiley.gif> ",$_POST['Tip']);> >
> > But, the following does replace the ":("?
> >
> > str_replace(":(", " <img
> > src=http://www.com.com/forum/emoticons/crying.gif> ",>> >
> >
> > --
> > --------
> > Jon Rosenberg
> >
> >
>
Jon Guest
-
Damian Brown #4
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...> $_POST['Tip']);> > 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(":)", " <img
> > > src=http://www.com.com/forum/emoticons/smiley.gif> ",> $_POST['Tip']);> > >
> > > But, the following does replace the ":("?
> > >
> > > str_replace(":(", " <img
> > > src=http://www.com.com/forum/emoticons/crying.gif> ",>> >> > >
> > >
> > > --
> > > --------
> > > Jon Rosenberg
> > >
> > >
> >
>
Damian Brown Guest
-
Jon #5
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("/\:\)/", " <img
src=http://www.com.com/forum/emoticons/smiley.gif> ", $post);
$post = preg_replace("/\;\)/", " <img
src=http://www.com.com/forum/emoticons/wink.gif> ", $post);
$post = preg_replace("/\:\(/", " <img
src=http://www.com.com/forum/emoticons/crying.gif> ", $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
-
Damian Brown #6
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...statement> 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("/\:\)/", " <img
> src=http://www.com.com/forum/emoticons/smiley.gif> ", $post);
>
> $post = preg_replace("/\;\)/", " <img
> src=http://www.com.com/forum/emoticons/wink.gif> ", $post);
>
> $post = preg_replace("/\:\(/", " <img
> src=http://www.com.com/forum/emoticons/crying.gif> ", $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>> >
> > 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
-
Justin Koivisto #7
Re: str_replace quirk
Damian Brown wrote:
We all are. The minute you think you have nothing left to learn about a> i'm just learning
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
-
matty #8
Re: str_replace quirk
Jon wrote:
Try using single quotes instead - if you're not interpolating a variable,> Why does the following not replace the ":)"?
> str_replace(":)", " <img
> src=http://www.com.com/forum/emoticons/smiley.gif> ", $_POST['Tip']);
>
> But, the following does replace the ":("?
>
> str_replace(":(", " <img
> src=http://www.com.com/forum/emoticons/crying.gif> ", $_POST['Tip']);
>
>
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(':)', ' <img src="http://www.com.com/icons/crying.gif" alt="Crying Smiley" /> ', $_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



Reply With Quote

