Jump to content

splitting string and making into seperate variables


dsaba

Recommended Posts

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

 

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.