dsaba Posted March 5, 2007 Share Posted March 5, 2007 i need some help with a new endeavour, i will list what I want to do, how I think it should be done and hopefully someone can tell me how to do this with php i am querying fieldnames from a table in a mysql database so lets say i query and make $filename = $row['filename'] lets say that this $filename = "Linux- version [2.0]-new (2006)"; so I get that string back first i want to remove these characters from the string: -, [, ], (, ) so now the string will look like: "Linux version 2.0new 2006" now I want to make keywords out of each word in the string and make variables for each keyword that i pull out i also want to make pretty keywords too, for example i dont want "2.0new" as a keyword rather: 2.0 is one keyword and new is another then i want to submit these variables back into the db as keywords in a new table i have researched split string functions but what i am confused about is how it will make the individual keywords, how it will differentiate 2.0new as two keywords rather than one and how I can make multiple keywords and different variables for each split i pull out of the string Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2007 Share Posted March 5, 2007 It's better if you don't remove the extra characters before splitting. Your question "How does it know 2.0 and new should be seperate?" is a good one. The answer is "It doesn't know". Instead, try this: $results = preg_split('|[\[\]() -]+|', $filename); Quote Link to comment Share on other sites More sharing options...
rcorlew Posted March 5, 2007 Share Posted March 5, 2007 you could also try using the substr() function if you know how many letters and symbols are in each filename and what position they are in. ex.. $stringtosplit = $filename; $key_1 = substr($stringtosplit, 0,5); $key_2 = substr($stringtosplit, 8,14); and so forth. The key would be know how many places are in each file name, that would only work if they are all named using the same name format. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted March 5, 2007 Share Posted March 5, 2007 Substring is a very bad way to do it unless you know, like you said, where everything is, and often times, you won't. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.