Alright, I'm getting data from an external API that scrapes market-data of the Steam market.
Now I'm getting a string as follows,
Desert Eagle | Night (Field-Tested)
Then what I'm trying to do is get what type of weapon it is, what it's name is and what wear it is.
This is what I'm trying to get it to put out,
Desert Eagle
Night
Field-Tested
or FT
This is the code I used to do this,
$item_wear = preg_replace('/^.*(\(.*\)).*$/', '$1', $item); //(Field-Tested)
$item_wear_short = preg_replace("/(?![A-Z])./", "", $item_wear); //FT
$exp_item_version = explode(" | ", str_replace($item_wear,"", $item)); //Array of Desert Eagle and Night
$item_version = $exp_item_version[0]; //Desert Eagle
$item_name = $exp_item_version[1]; //Night
That's basically what I've done, but now if there's an item named like,
Chroma Case Key
It'll do all sorts of stuff, while with strings that don't have a wear or anything I'd just like it so the $item_name
is Chroma Case Key
and the other strings just return empty, any proper way of doing this? also the code I used looks pretty messy in my opinion, anything I could change?