How to create an algorithm which creates a word search puzzle?

I would love to create a word search puzzle on the web where I can input the words in an array, and then the puzzle will be generated with those words placed randomly in a grid.

Something like this:
enter image description here

I found a tutorial, but it was not exactly what my problem described: Word Search

Because you had to put the words in the table yourself by changing the html.

If anyone has any ideas to create this word search puzzle, please tell me.