Log in

View Full Version : PHP Parsing Question



rate
04-26-2008, 09:42 AM
Is the following process possible:

1. Enter a text string into a form such as:

"Dynamic Forums. DHTML Scripts for the real world."

2. Submit the string to a PHP script and store in a variable.

3. The script parses the text string on the word level.

4. The script stores each word into a variable such as:

$word1 = Dynamic
$word2 = Forum
$word3 = DHTML
.
.
.
.
$word8 = world

Thanks

rate
04-26-2008, 09:53 AM
I think I found the answer to my own question. I'll research the explode function.

gdhanasekar
04-26-2008, 11:17 AM
Hi try this code

$string_to_parse="word1 word2";
$parsedarr=explode(" ",$string_to_parse);
print_r($parsedarr);


Cheers!!!
gdhansekar
http://www.php-web-developer.net/

rate
04-26-2008, 05:54 PM
What if I use the results of explode in a conditional select statement, is there a way periods that are at the end of some words? For example in the first post, if I used explode in the sentence, one of the array elements would be [7]=word.

If I feed this to a conditional select statement using the WHERE clause, it wouldn't find "word." when it should be looking for "word"

tfit
04-26-2008, 06:44 PM
you mean $word[7] = "world". select 'field' from 'table' where $word[7] == some field value? Sorry, database of course should be table. fixed it now :-)