Shoutbox

php smilie code check - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: php smilie code check (/showthread.php?tid=54230)

php smilie code check by stoshrocket on 12-24-2005 at 02:45 PM

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
RE: php smilie code check by user27089 on 12-24-2005 at 02:46 PM

str_replace("0Smilie", "<img alt="smiley" src='smilies/angel.gif' />",

it might be the "0" before the smilie...


RE: php smilie code check by stoshrocket on 12-24-2005 at 02:47 PM

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...
RE: php smilie code check by Ezra on 12-24-2005 at 02:55 PM

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" />',


RE: php smilie code check by Stigmata on 12-24-2005 at 03:13 PM

code:
$text = preg_replace("(a)", "<img alt='smiley' src='smilies/angel.gif' />", $text)


That will work perfectly.
RE: php smilie code check by Plik on 12-24-2005 at 03:15 PM

* 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 :P

*i havnt tested it :P
RE: php smilie code check by absorbation on 12-24-2005 at 03:47 PM

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 :P (just an heads up php is not like javascript for stuff like this ;) )
RE: php smilie code check by stoshrocket on 12-24-2005 at 03:49 PM

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!
RE: php smilie code check by Veggie on 12-24-2005 at 04:33 PM

is the text you type in the $text variable?


RE: php smilie code check by stoshrocket on 12-24-2005 at 04:36 PM

quote:
Originally posted by Veggie
is the text you type in the $text variable?

:S explain please :$
RE: php smilie code check by Veggie on 12-24-2005 at 04:54 PM

$text = "hello test :o";

then string replace

then
echo $text;


RE: php smilie code check by stoshrocket on 12-24-2005 at 05:06 PM

quote:
Originally posted by Veggie
$text = "hello test :o";

then string replace

then
echo $text;

ok, im well and truly baffled. i think it would be quicker with the <img src=".."> code... lol, thanks anyway!
RE: php smilie code check by Plik on 12-24-2005 at 05:11 PM

quote:
Originally posted by Methos2
quote:
Originally posted by Veggie
$text = "hello test :o";

then string replace

then
echo $text;

ok, im well and truly baffled. i think it would be quicker with the <img src=".."> code... lol, thanks anyway!

What he wants is for you to set $text to "hello test :[b][/b]o" then perform the replace and then echo $text and tell us what it outputs.
Also could you post your complete $smiley_list and $replacement_list, arrays? (the two limes that start with $smiley_list = Array, and $replacement_list = Array)
RE: php smilie code check by hmaster on 12-24-2005 at 05:12 PM

He means that the code will only work if you put the text in the $text variable.

This is my news post 0:) :D :)

code:
<?php

$text = "This is my news post  0:) :D :)[";

$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);

echo $text;
?>

lol @Madman ;)
RE: php smilie code check by stoshrocket on 12-24-2005 at 07:58 PM

quote:
Originally posted by hmaster
He means that the code will only work if you put the text in the $text variable.

This is my news post 0:) :D :)

code:
<?php

$text = "This is my news post  0:) :D :)[";

$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);

echo $text;
?>



but having to to do this throughout the code deifes the object of a 'shortcut' such as :), unless i have missed something here it would be alot simpler and quicker to just use the html tag <img> wouldnt it.... :undecided:
RE: php smilie code check by hmaster on 12-24-2005 at 08:03 PM

In your case yes. But it depends how you do it.
Something like WordPress does not rely on FTP to add new blog/news posts. It has a form, which then can be easier to add scripts too.


RE: php smilie code check by Plik on 12-24-2005 at 08:15 PM

quote:
Originally posted by Methos2
quote:
Originally posted by hmaster
He means that the code will only work if you put the text in the $text variable.

This is my news post 0:) :D :)

code:
<?php

$text = "This is my news post  0:) :D :)[";

$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);

echo $text;
?>



but having to to do this throughout the code deifes the object of a 'shortcut' such as :), unless i have missed something here it would be alot simpler and quicker to just use the html tag <img> wouldnt it.... :undecided:

The whole point in that is to test that you are setting the $text variable correctly and that you are executing the function correctly, you wont have to do that for the code once whe can make sure that it is working correctly.
also:
quote:
Originally posted by Madman
could you post your complete $smiley_list and $replacement_list, arrays? (the two limes that start with $smiley_list = Array, and $replacement_list = Array)

RE: php smilie code check by stoshrocket on 12-24-2005 at 08:18 PM

ok, it shows as it should, it replaces the smilies with the appropriate pics, and as for the code, ill just go and fetch it.....
this is the whole php code that is in the document::

code:
<?php
$smiley_list = array(":)", "0:)", ":D", ":S", "B)", ":'(", ":$",
":|", "8-)", "^o)", ":o", ":P", ";)", ":refuck:", ">(", "='(",
"=D", "O.o", "=(", "=)", "=P", "=/", );
$replacement_list = array(
'<img alt="smilie" src="smilies/grin.gif" />',
'<img alt="smilie" src="smilies/angel.gif" />',
'<img alt="smilie" src="smilies/biggrin.gif" />',
'<img alt="smilie" src="smilies/confuzzled.gif" />',
'<img alt="smilie" src="smilies/cool.gif" />',
'<img alt="smilie" src="smilies/cry.gif" />',
'<img alt="smilie" src="smilies/embarrassed.gif" />',
'<img alt="smilie" src="smilies/notamused.gif" />',
'<img alt="smilie" src="smilies/rolleyes.gif" />',
'<img alt="smilie" src="smilies/sarcastic.gif" />',
'<img alt="smilie" src="smilies/shock.gif" />',
'<img alt="smilie" src="smilies/tongue.gif" />',
'<img alt="smilie" src="smilies/wink.gif" />',
'<img alt="smilie" src="smilies/refuck.gif" />',
'<img alt="smilie" src="smilies/bangry.gif" />',
'<img alt="smilie" src="smilies/bcry.gif" />',
'<img alt="smilie" src="smilies/blaugh.gif" />',
'<img alt="smilie" src="smilies/bwassat.gif" />',
'<img alt="smilie" src="smilies/bsad.gif" />',
'<img alt="smilie" src="smilies/bsmile.gif" />',
'<img alt="smilie" src="smilies/btongue.gif" />',
'<img alt="smilie" src="smilies/bwink.gif" />',
);
$text = str_replace($smiley_list, $replacement_list, $text);
?>


RE: php smilie code check by Plik on 12-24-2005 at 08:29 PM

quote:
Originally posted by Methos2
ok, it shows as it should, it replaces the smilies with the appropriate pics, and as for the code, ill just go and fetch it.....
this is the whole php code that is in the document:
Then if it works as it should if you set the the $text variable in the script then the problem is caused by how you set the $text variable to your input.
RE: php smilie code check by stoshrocket on 12-24-2005 at 08:33 PM

quote:
Originally posted by Madman
quote:
Originally posted by Methos2
ok, it shows as it should, it replaces the smilies with the appropriate pics, and as for the code, ill just go and fetch it.....
this is the whole php code that is in the document:
Then if it works as it should if you set the the $text variable in the script then the problem is caused by how you set the $text variable to your input.

its not a case of it not working.... its just a case of that...

quote:
Originally posted by Methos2
but having to to do this throughout the code deifes the object of a 'shortcut' such as :), unless i have missed something here it would be alot simpler and quicker to just use the html tag <img> wouldnt it....

RE: php smilie code check by Plik on 12-24-2005 at 08:38 PM

quote:
Originally posted by Methos2
quote:
Originally posted by Madman
quote:
Originally posted by Methos2
ok, it shows as it should, it replaces the smilies with the appropriate pics, and as for the code, ill just go and fetch it.....
this is the whole php code that is in the document:
Then if it works as it should if you set the the $text variable in the script then the problem is caused by how you set the $text variable to your input.

its not a case of it not working.... its just a case of that...

quote:
Originally posted by Methos2
but having to to do this throughout the code deifes the object of a 'shortcut' such as :), unless i have missed something here it would be alot simpler and quicker to just use the html tag <img> wouldnt it....


i dont understand what you mean :-/
if you set $text to whatever you want to convert for example $text = $_POST['text'] and then use the replace function, then $text will now contain the text you inputed (e.g. $_POST['text']) but the shortcuts will have been replaced by the image codes.
So i dont see what you have to "do" that defeats the point of using the shortcuts.
Could you perhaps upload the script your testing so we can test it and understand what your trying to acheive?

RE: php smilie code check by stoshrocket on 12-24-2005 at 08:43 PM

right, look at my website for example, http://methos2.skarz.co.uk/test/ here i use php to create the template then include different files for different pages, and the php is in the head tag of index.php, what i want to do is, because i change the content quite regularly, i want it so that no matter where in the content, all i ahve to do is type :) and a smilie will replace it with the image, and i want the to appear throughout the page numerous times in numerous posts wherever i post them, do you understand me or am i going to have to make a quick exapmle of what i want? :p;)


RE: php smilie code check by Plik on 12-24-2005 at 08:55 PM

So you're including files with the function include? If so, how are you setting the $text variable before performing str_replace on it? If you want you can add me to msn, my address is in my sig on my profile


RE: php smilie code check by stoshrocket on 12-24-2005 at 09:00 PM

quote:
Originally posted by Madman
So you're including files with the function include? If so, how are you setting the $text variable before performing str_replace on it? If you want you can add me to msn, my address is in my sig on my profile

i think your forgetting your talking to a noob of php here.... lol, ill add you, my names andi btw, just so you knwo its me adding you ;)