任何人都可以建议从字符串中找到单词吗?

I am using PHP/MYSQL for my major project in college. It is a search engine I made.

My database contain results for this sentence 'who is the first president of america'.

My question is, when user enter the same query without white space (e.g.: 'whoisthefirstpresidentofamerica') my search engine fails to retrieve results from the database.

Is there anyway to find words from string which doesn't contain spaces?

Use LIKE keyword

select * from tablename where fieldname LIKE 'value%';

You can do the comparison by removing all spaces from both strings:

select *
from t
where replace(t.col, ' ', '') = replace(@Val, ' ', '')

However, I suspect that you want to use the full text search capabilities of MySQL. If you are dealing with sentences, this is by far the better way to go. You can start learning about them here.

EDIT:

If your purpose is to investigate different ranking algorithms, then you need to learn about text search and analysis. A good place to start is with the MySQL documentation on full text search. However, it does not let you customize the ranking methods very easily.

In particular, you should be storing your text in a "document-term" format. That is, have a sentence be split into multiple rows, one for each term in the sentence, along with a word-position column. This will give you flexibility you need to investigate your own ranking algorithms.