Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Html and Javascript to Php

    Hello Every 1 .

    How to convert this Html code ,(with jave ) to Php
    PHP Code:
                   <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;
                            
    txtarea.focus();
                         } else {
                            
    txtarea.value  += text;
                            
    txtarea.focus();
                         }
                      }
                   
    </script>

    <!-- 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>
                      </tr>
        
    </table>

    <!-- Smiley List Stops Here --> 
    Last edited by ajloun; 09-01-2009 at 12:24 PM.

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    PHP outputs HTML and Javascript. You do not need to convert html/javascript to PHP.





    ---------------
    Leonard Whistler

  • Users who have thanked Len Whistler for this post:

    ajloun (09-01-2009)

  • #3
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    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 is a good way to convert something like :-) to an image

    example:
    PHP Code:
    $text str_replace(':)''<img src="url.jpg" />'$text); 
    Thus replacing
    Code:
    :)
    with an image.
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • Users who have thanked Zangeel for this post:

    ajloun (09-01-2009)

  • #4
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    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

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Perhaps you should read this page in the PHP Manual:

    http://www.php.net/manual/en/intro-whatis.php

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

  • Users who have thanked Fumigator for this post:

    ajloun (09-01-2009)

  • #6
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Can you Tell me exactly how to use the Above code with this php Form
    PHP Code:
           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>"

  • #7
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    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
    PHP Code:
    <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>
    <tr>
    <td class="odd">
    <input type="text" value="<?php echo "$unkame"?>" name="name" size="20" maxlength="20"></td>
    </td><td>
    <textarea rows=4 cols=75 name=comment wrap=physical></textarea>
    <input type="hidden" name="submitter" value="<?php echo "$umid"?>"></input>
    <tr>
    <input type="submit" name="submit" value="">
    </table>
    </form>
    Leonard Whistler

  • Users who have thanked Len Whistler for this post:

    ajloun (09-01-2009)

  • #8
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Thank you , Pretty Good Clean Up


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •