Header Ads Widget

How to create a simple English to Bangla dictionary generator using PHP

To create an English to Bangla dictionary using PHP, you could use the following code:

< ?php

// Set up the English to Bangla dictionary
$dictionary = array(
  "hello" => "হ্যালো",
  "world" => "ওয়ার্ল্ড",
  "apple" => "আপেল",
  "book" => "বই",
  "cat" => "বিড়াল"
);

// Function to translate English to Bangla
function translate($word) {
  global $dictionary; // Use the global dictionary
  if (isset($dictionary[$word])) { // Check if the word is in the dictionary
    return $dictionary[$word]; // Return the translated word
  }
  else {
    return "Word not found in dictionary."; // Return an error message
  }
}

// Test the translation function
echo translate("hello"); // Outputs "হ্যালো"
echo translate("cat"); // Outputs "বিড়াল"
echo translate("dog"); // Outputs "Word not found in dictionary."

?>

This code defines an array called $dictionary that contains the English to Bangla translations. It also defines a function called translate that takes a word as an argument and returns the translated word if it is found in the $dictionary array, or an error message if it is not. The code then tests the function by calling it with different words and printing the output.

Post a Comment

0 Comments