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
PHP Newb: Dynamic Array
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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:
Then you use the explode() http://php.net/explode function, which returns an array.
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.
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 spaceCode: Select all
$your_array = explode(" ",$string_you_want_to_convert);I think that gave you a hint how to do this yourself.