Page 1 of 1
PHP Newb: Dynamic Array
Posted: Tue Jun 17, 2003 10:34 am
by thrustinj
I'm trying to take a search string and make an array out of it. I'm better this in ASP.
How do you declare an array or do you even have to?
This is my string convert:
$commentsArray[] = preg_split("", $comments, -1, PREG_SPLIT_DELIM_CAPTURE)
I also want it to split based on spaces and commas.
I just bought for php too...
Thanks for the help
Posted: Tue Jun 17, 2003 10:37 am
by twigletmac
Could you give us an example of the string that you are trying to explode into an array and an idea of what you need to split it on.
Mac
Posted: Tue Jun 17, 2003 10:44 am
by thrustinj
Well..it's a key word field for a search page. So I have to be ready for spaces, commas...anything people would write to seperate words on. Basically something like:
africa dog nigeria
Posted: Tue Jun 17, 2003 11:00 am
by delorian
I think you don't need commas, semi-colons, dots etc. in your search engine so the thing to do is to convert those marks to spaces, like:
Code: Select all
ereg_replace(","," ",$string_you_want_to_convert);
// the same with other marks
// it is also good to convert double spaces into one space
Then you use the explode()
http://php.net/explode function, which returns an array.
Code: Select all
$your_array = explode(" ",$string_you_want_to_convert);
If you don't change double spaces into one space you will have some empty fields in $your_array.
I think that gave you a hint how to do this yourself.
Posted: Tue Jun 17, 2003 12:18 pm
by thrustinj
okay..i think this is working. I'll be back in this thread if anything else comes up related to it.
Thanks!