Jump to content

Thesaurus


KenJuma

Recommended Posts

I'm new to php and my first assignment is to design a project that give a user synonyms to words and also allows the user to add words and their synonyms. The thesaurus doesnt have to be full of all the words, an example of two or three words would just be enough. I do not want to use a database since I want to fullu understand php before starting to interact with databases. Someone told me I could save the words in some file which will be accessed by the codes and when the user enters the new words, they would automatically be updated in the file. I was thinking of using arrays, any help..?

Link to comment
Share on other sites

You cannot "fully understand" PHP without interacting with a database. PHP and MySQL really go hand in hand, especially when you're talking about storing data.

 

But yes, you can store data in a file. You can find many tutorials on file read/write if you google it. 

Link to comment
Share on other sites

In a "real" application, one would of course use a database for this, but I understand that you want to move forward slowly and not learn everything at once. As Jessica said, you would almost always be using a database for storage, so learning how to do this by file probably won't help you out that much in the future anyways. Using a database also makes it easier to make relationships between data such as words. For instance, one could make relationships between words that indicate that they are synonyms instead of replicating the words in PHP (avoiding this would probably get more complicated than it really has to be).

 

Either way, here is a quick example of how you could use arrays in PHP for this. Surely there are better ways (especially if you use a database), but perhaps it is enough to get you started.

 


$words = array(
'beautiful' => array('handsome', 'pretty', 'lovely'),
'funny' => array('comical', 'amusing', 'humorous', 'laughable'),
'clever' => array('smart', 'intelligent', 'ingenious')
);

 

To save it to a file, you can can serialize the array (Google should help you out here).

 

Each word has an array of synonyms. Imagine that for each of those words, you would have an array of all of the other synonyms. For instance, an entry for the word "smart" would have an array of "clever", "intelligent", "ingenious", and so on. You can use references, but I think you will end up overcomplicating things - and worse yet, you will probably not be able to leverage so much from the experience since it is probably far away from what you will face when doing "real" applications. So my advice is to keep it as close to how you would do it if you were paid to do it for someone.

 

Good luck!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.