View Full Version : Resolved Html and Javascript to Php

08-31-2009, 10:12 PM
Hello Every 1 .

How to convert this Html code ,(with jave ) to Php

<script type="text/javascript">
function emoticon(text) {
var txtarea = document.getElementById("form").comment;
text = ' ' + text + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
} else {
txtarea.value += text;

<!-- Smiley List Starts Here -->

<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr align="center" valign="middle">
<td><a href="javascript:emoticon(':hammer:')"><img src="smileys/icon_biggrin.gif" border="0" alt="Hammer" title="Hammer"></a></td>
<td><a href="javascript:emoticon(':-)')"><img src="smileys/icon_smile.gif" border="0" alt="Smile" title="Smile"></a></td>
<td><a href="javascript:emoticon(':-(')"><img src="smileys/icon_sad.gif" border="0" alt="Sad" title="Sad"></a></td>
<td><a href="javascript:emoticon(':-o')"><img src="smileys/icon_surprised.gif" border="0" alt="Surprised" title="Surprised"></a></td>
<td><a href="javascript:emoticon(':roll:')"><img src="smileys/icon_confused.gif" border="0" alt="Confused" title="Confused"></a></td>
<td><a href="javascript:emoticon(':lol:')"><img src="smileys/icon_cool.gif" border="0" alt="Cool" title="Cool"></a></td>
<td><a href="javascript:emoticon(':-P')"><img src="smileys/icon_lol.gif" border="0" alt="Laughing" title="Laughing"></a></td>
<td><a href="javascript:emoticon(':evil:')"><img src="smileys/icon_mad.gif" border="0" alt="Mad" title="Mad"></a></td>
<td><a href="javascript:emoticon(':idea:')"><img src="smileys/icon_razz.gif" border="0" alt="Razz" title="Razz"></a></td>


<!-- Smiley List Stops Here -->

Len Whistler
08-31-2009, 10:31 PM
PHP outputs HTML and Javascript. You do not need to convert html/javascript to PHP.


08-31-2009, 10:47 PM
You want to convert the functionality of the java-script function to php? You could, even though it wont be cosmetically as pleasing. str_replace (http://php.net/str_replace) is a good way to convert something like :-) to an image


$text = str_replace(':)', '<img src="url.jpg" />', $text);

Thus replacing
:) with an image.

08-31-2009, 11:04 PM
Thank you ,
i might was not clear , but wht i need is to use the code above with php file already exist and has some php codes and functions , i cant just insert it .. i tried to insert it after ?> didt work . or didt work Good

08-31-2009, 11:32 PM
Perhaps you should read this page in the PHP Manual:


That gives you an idea of how PHP handles raw HTML and Javascript code.

09-01-2009, 01:41 AM
Can you Tell me exactly how to use the Above code with this php Form

echo "<form action=\"post.php\" method=\"post\">\n";
echo "<table class=\"outer\" width=\"100%\" cellspacing=\"1\" cellpadding=\"0\" border=\"0\">\n";
echo "<tr>\n";
echo "<th>"._MD_MSGNAME."</th>\n";
echo "<th>"._MD_SEND."</th>\n";
echo "</tr>";
echo "<tr>";
echo "<td class=\"odd\">\n";
echo "<input type=\"text\" value=\"$unkame\" name=\"name\" size=\"20\" maxlength=\"20\"></td>\n";
echo "</td><td>";
echo "<textarea rows=4 cols=75 name=comment wrap=physical></textarea>";
echo "<input type=\"hidden\" name=\"submitter\" value=\"$umid\"></input>";
echo "<tr>\n";
echo "<td class=\"odd\">\n";
echo "<input type=\"submit\" name=\"submit\" value=\""._MD_."\"></p>\n";
echo "</table>";
echo "</form>";

Len Whistler
09-01-2009, 05:18 AM
You don't need all those echoes, I cleaned it up a bit. Below is a quick example but it's incomplete and syntax isn't perfect. You had some odd tags such as a closing p after your form submit button and tr before th. th is header and is always the first row, no need to enclose th /th inside a tr /tr

Below still need some work

<form action="post.php" method="post">
<table class="outer" width="100%" cellspacing="1" cellpadding="0" border="0">
<th><?php echo "._MD_MSGNAME."; ?></th><th><?php echo "._MD_SEND."; ?></th>
<td class="odd">
<input type="text" value="<?php echo "$unkame"; ?>" name="name" size="20" maxlength="20"></td>
<textarea rows=4 cols=75 name=comment wrap=physical></textarea>
<input type="hidden" name="submitter" value="<?php echo "$umid"; ?>"></input>
<input type="submit" name="submit" value="">

09-01-2009, 12:23 PM
Thank you , Pretty Good Clean Up