Online Dictionary Website - Any suggestion or Direction?

Discussion in 'Programming' started by Johnscore, May 5, 2011.

  1. #1
    I am planning to create English to Mizo Online Dictionary but i am not aware of how to make it. I know only little about PHP and html. In php, which criteria am I going to emphasize learning to make online dictionary. I prefer to make it on my own rather than free scripts or softwares. Please any Suggestion or any tutorial? Because i am not afforded to buy or hire someone. Thanks in advance.
    :D
     
    Johnscore, May 5, 2011 IP
  2. CrowdA

    CrowdA Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Check out Glossum.
     
    CrowdA, Jul 24, 2011 IP
  3. dthoai

    dthoai Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    38
    #3
    Following is simple dictionary. Please use it for reference.

    library.php
    
    <?php
    
    $dbcfg['Database'] = 'Your database';
    $dbcfg['Username'] = 'Your username';
    $dbcfg['Password'] = 'Your password';
    $dbcfg['Prefix'] = 'emod_';
    $dbcfg['Storage'] = 'location which store definition files';
    
    $link = mysql_connect('localhost', $dbcfg['Username'], $dbcfg['Password']);
    mysql_select_db($dbcfg['Database'], $link);
    
    function table($name) {
      global $dbcfg;
      return $dbcfg['Prefix'].$name;
    }
    
    function quote($src) {
      return "'".mysql_real_escape_string($src)."'";
    }
    
    function execute($sql) {
      global $link;
      mysql_query($sql, $link);
    }
    
    function query($sql) {
      global $link;
      $target = array();
      $result = mysql_query($sql, $link);
      while ($row = mysql_fetch_assoc($result)) {
        $target[] = $row;
      }
      return $target;
    }
    
    function post($name) {
      if (!isset($_POST[$name])) return '';
      return $_POST[$name];
    }
    
    function get($name) {
      if (!isset($_GET[$name])) return '';
      return $_GET[$name];
    }
    
    function isPost() {
      $method = strtolower($_SERVER['REQUEST_METHOD']);
      return $method == 'post';
    }
    
    function install() {
      execute(sprintf("create table %s (code varchar(32) not null, english varchar(255) not null, primary key code);", table('definition')));
    }
    
    function addword($english, $mizo) {
      global $dbcfg;
      $code = uniqid();
      file_put_contents($dbcfg['Storage'] . $code . '.html');
      execute(sprintf("insert into %s values (%s, %s)", table('definition'), quote($code), quote($english)));
    }
    
    function findword($keyword) {
      $data = query(sprintf('select * from %s where english like '%%s%', table('definition'), quote($keyword)));
      global $dbcfg;
      $tag = array();
      for ($i = 0; $i < count($data); $i++) {
        $code = $data[$i]['code'];
        $english = $data[$i]['english'];
        $tag[$english] = file_get_contents($dbcfg['Storage'] . $code . '.html');
      }
      return $tag;
    }
    
    ?>
    
    Code (markup):
    install.php
    
    <?php
    require('library.php');
    install();
    ?>
    
    Code (markup):
    addword.php
    
    <?php
    require('library.php');
    if (isPost()) {
      $english = post('english');
      $mizo = post('mizo');
      addword($english, $mizo);
      header('Location: addword.php');
    } else {
    ?>
    <html>
    <body>
    <form action="addword.php" method="post">
      <table>
        <tr>
          <td>English:</td>
          <td><input type="text" name="english"></td>
        </tr>
        <tr>
          <td>Mizo:</td>
          <td><textarea cols="50" rows="20"></textarea></td>
        </tr>
        <tr>
          <td colspan="2"><input type="submit" value="Add"></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    <?php
    }
    ?>
    
    Code (markup):
    findword.php
    
    <?php
    require('library.php');
    if (isPost()) {
      $english = post('english');
      $data = findword($english, $mizo);
    ?>
    <html>
    <body>
    <?php
      foreach ($data as $english => $mizo) {
    ?>
    <p><?php echo $mizo ?></p><hr>
    <?php
      }
    ?>
    <input type="button" value="Return" onclick="location.replace('findword.php')">
    </body>
    </html>
    <?php
    } else {
    ?>
    <html>
    <body>
    <form action="findword.php" method="post">
      <table>
        <tr>
          <td>English:</td>
          <td><input type="text" name="english"></td>
        </tr>
        <tr>
          <td colspan="2"><input type="submit" value="Add"></td>
        </tr>
      </table>
    </form>
    </body>
    </html>
    <?php
    }
    ?>
    
    Code (markup):
     
    dthoai, Jul 25, 2011 IP