php smilie code check |
Author: |
Message: |
stoshrocket
Senior Member
formerly methos
Posts: 748 Reputation: 31
34 / /
Joined: Aug 2005
|
O.P. php smilie code check
ok, im crap at php, but give me a chance, atleast ive tried ok, this code is meant to replace smilie symbols with the image of the smilie, but when uploaded the whole page just gives me
'Parse error: parse error, unexpected T_STRING in /home2/skarz/public_html/methos2/test/index.php on line 19'
the code is as follows, it is included in the <head> tag and it starts from line 17 where <?php is...
code: <?php
$text = str_replace(":)", "<img alt="smiley" src='smilies/grin.gif' />",
str_replace("0:)", "<img alt="smiley" src='smilies/angel.gif' />",
str_replace(":D", "<img alt="smiley" src='smilies/biggrin.gif' />",
rest of smilie code here, it takes too much room
$text);
?>
anyone see whats causing the error? thanks
This post was edited on 12-24-2005 at 02:49 PM by stoshrocket.
|
|
12-24-2005 02:45 PM |
|
|
user27089
Disabled Account
Posts: 6321
Joined: Nov 2003
Status: Away
|
RE: php smilie code check
str_replace("0Smilie", "<img alt="smiley" src='smilies/angel.gif' />",
it might be the "0" before the smilie...
|
|
12-24-2005 02:46 PM |
|
|
stoshrocket
Senior Member
formerly methos
Posts: 748 Reputation: 31
34 / /
Joined: Aug 2005
|
O.P. RE: php smilie code check
quote: Originally posted by traxor
str_replace("0Smilie", "<img alt="smiley" src='smilies/angel.gif' />",
it might be the "0" before the smilie...
nope, thats just the actual symbol that would trigger it to replace it with angel.gif, wouldnt it, hang on, ill bold the line its saying i have an error on...
|
|
12-24-2005 02:47 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
RE: php smilie code check
cause you are using "" to enclose the strings and because you put "smiley" between them too it's not enclosed. I recommend using ' to enclose strings so you can use the " for html enclosing.
code: $text = str_replace(':)', '<img alt="smiley" src="smilies/grin.gif" />',
This post was edited on 12-24-2005 at 03:02 PM by Ezra.
|
|
12-24-2005 02:55 PM |
|
|
Stigmata
Veteran Member
Posts: 3520 Reputation: 45
21 / /
Joined: Jul 2003
|
RE: php smilie code check
code: $text = preg_replace("(a)", "<img alt='smiley' src='smilies/angel.gif' />", $text)
That will work perfectly.
This post was edited on 12-24-2005 at 03:16 PM by Stigmata.
|
|
12-24-2005 03:13 PM |
|
|
Plik
Veteran Member
Posts: 1489 Reputation: 46
35 / / –
Joined: Jun 2004
|
RE: php smilie code check
* Plik pukes
i suggest you read up on the basic php syntax because what your trying to do is horibly wrong, but to get you started this should* work
code:
<?php
$smiley_list = array(":)", "0:)", ":D", the rest of the smilies);
$replacement_list = array('<img alt="smiley" src="smilies/grin.gif" />', '<img alt="smiley" src="smilies/angel.gif" />', '<img alt="smiley" src="smilies/biggrin.gif" />', The rest of the replacements here, using this format: '<img alt="alttext" src="location' />");
$text = str_replace($smiley_list, $replacement_list, $text);
?>
If you are unsure about a function always refer to http://php.net
str_replace
also stiggys way works for each one
*i havnt tested it
|
|
12-24-2005 03:15 PM |
|
|
absorbation
Elite Member
Posts: 3636 Reputation: 81
– / /
Joined: Feb 2005
|
RE: php smilie code check
quote: Originally posted by Methos2
it is included in the <head> tag
it should not matter, you can place the php anywhere it will excute in the same way, you only really want php in a disired place where you want to php to display content using print or echo (just an heads up php is not like javascript for stuff like this )
|
|
12-24-2005 03:47 PM |
|
|
stoshrocket
Senior Member
formerly methos
Posts: 748 Reputation: 31
34 / /
Joined: Aug 2005
|
O.P. RE: php smilie code check
quote: Originally posted by Madman
* Madman pukes
i suggest you read up on the basic php syntax because what your trying to do is horibly wrong, but to get you started this should* work
code:
<?php
$smiley_list = array(":)", "0:)", ":D", the rest of the smilies);
$replacement_list = array('<img alt="smiley" src="smilies/grin.gif" />', '<img alt="smiley" src="smilies/angel.gif" />', '<img alt="smiley" src="smilies/biggrin.gif" />', The rest of the replacements here, using this format: '<img alt="alttext" src="location' />");
$text = str_replace($smiley_list, $replacement_list, $text);
?>
If you are unsure about a function always refer to http://php.net
str_replace
also stiggys way works for each one :P
*i havnt tested it :P
ok, thats stopped the errors running up although, am i missing something, its still showing up as :o when i type it, oh noes!
|
|
12-24-2005 03:49 PM |
|
|
Veggie
Full Member
Posts: 415 Reputation: 21
37 / /
Joined: Sep 2004
|
RE: php smilie code check
is the text you type in the $text variable?
|
|
12-24-2005 04:33 PM |
|
|
stoshrocket
Senior Member
formerly methos
Posts: 748 Reputation: 31
34 / /
Joined: Aug 2005
|
O.P. RE: php smilie code check
quote: Originally posted by Veggie
is the text you type in the $text variable?
explain please
This post was edited on 12-24-2005 at 04:36 PM by stoshrocket.
|
|
12-24-2005 04:36 PM |
|
|
Pages: (3):
« First
[ 1 ]
2
3
»
Last »
|
|