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 7 4588
Forgot to add....I am running PHP 4.3.0.
"Jon" <ru*******@hotmail.com> wrote in message
news:vk************@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
Duh, stupid me. Thanks for pointing that out to me.
"Damian Brown" <da****@phpexpert.org> wrote in message
news:bh**********@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 www.phpexpert.org/chat/ UK FREEphone 0800 019 0924
"Jon" <ru*******@hotmail.com> wrote in message news:vk************@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
it was good to be of assistance
you can reach me on CHAT
at www.phpexpert.org/chat/
if you have any further problems
Regards,
Damian www.phpexpert.org
UK FREEphone 0800 019 0924
"Jon" <ru*******@hotmail.com> wrote in message
news:vk************@corp.supernews.com... Duh, stupid me. Thanks for pointing that out to me.
"Damian Brown" <da****@phpexpert.org> wrote in message news:bh**********@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 www.phpexpert.org/chat/ UK FREEphone 0800 019 0924
"Jon" <ru*******@hotmail.com> wrote in message news:vk************@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
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" <za**@buennagel.com> wrote in message
news:bh*************@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 http://www.sourceforge.net/projects/zang */
i'm glad you got it going
i'm no expert, i'm just learning
"Jon" <ru*******@hotmail.com> wrote in message
news:vk************@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("/\:\)/", " <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" <za**@buennagel.com> wrote in message news:bh*************@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 http://www.sourceforge.net/projects/zang */
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 - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.
Jon wrote: 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']);
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(':)', ' <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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hugo Coolens |
last post by:
I need to use the str_replace function for a php-script which works
together with html/javascript.
In the script I have to perform things like:
$arabic=str_replace ("'","\'", $row);
$arabic=str_replace ("sh", "\š", $row);
the second line works perfectly, however I can't make the first one
work, it should replace a single quote with a quote...
|
by: marcomputers |
last post by:
Hi,
I'm trying to automatically update an existing rss podcast file using
php and the str_replace function.
Every time I add a media file, it should read the .rss file into a
string, take the closing </channel> and </rss> tags out of it, and add
the new rss file info to the end of the existing string, writing it
back to the rss file....
|
by: Wayne |
last post by:
$a = $_POST; # txt_content = This is a<CR><LF>Test
$p = str_replace ("%0D%0A", "<br>", $a);
That is the above code that I am using, however, it is not picking up
the CR/LF from the textarea. I have also attempted singular variations
of the CR/LF combination and even reversed the sequence without success.
Is it possible that it may be...
|
by: The Numerator |
last post by:
I have this page (print.php). In that file, I want to to include a text
file from "songs/breathe.txt", and replace all instances of "<b" with
"<span" and "</b>" with "</span>". I know how I should use str_replace
and I tried to do this:
<?php
$replace_a=str_replace("<span","<b",include("text/breathe.txt"));...
|
by: d1srupt3r |
last post by:
I am developing my form into a captcha secured form and I used header() function if the user didn't put the verification code properly and still when the user go back to the form page the filled he have filled have still remained. In addition, users are usually submitting multiliner texts in the textbox so I used the str_replace() function to make...
| |
by: jmark |
last post by:
I saw this example in php.net
// Outputs: apearpearle pear
$letters = array('a', 'p');
$fruit = array('apple', 'pear');
$text = 'a p';
$output = str_replace($letters, $fruit, $text);
echo $output;
and I am bit puzzled why the output is the way it is instead of
|
by: Confused but working on it |
last post by:
So I've been trying to get a bit of code to:
Read all of the files in a dir called thumbs, but not the . and .., use
the filename in a link to get the same filename in an images dir. Now
I'm trying to use a foreach and glob as suggested, and get rid of the
part of the string that has the dir info. SO the below produces all my
thumbs nicely...
|
by: Sean Kim |
last post by:
From example in the book 'Programming PHP' (O'Reilly) (p.305)
$theKey = 'DESTINATION';
$target = '{' . $theKey . '}';
$inValues = 'some.php';
//$theTemplate = str_replace("\{$theKey}", $inValues,
theTemplate);
//$theTemplate = str_replace("{$theKey}", $inValues,
theTemplate);
|
by: jodleren |
last post by:
Hi all
I have text area, where I can edit files - but I have to correct the
returned data, for that I use
$content=str_replace('\"', '"', $content);
and
$content=str_replace('\\', '\', $content);
by some reason the latter one causes an error: syntax error,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |