0

I have a problem with regular expressions in PHP.

I have a string: "NAPLAK ROSSO+S.ARG.+LACC.ARG.+NK", all of this words contain options like ROSSO,S.ARG, Are colors ROSSO = Red, s.arg = silver and so on.

Out of this string i need to generate a description like:

Material: Naplak, Color: Red, Silver.... ....

I thought, that there is going to be an array with laguage codes something like this:

$options = array(
    "ROSSO" => "COLOR_RED",
    "S.ARG" => "COLOR_SILVER"
);

Could you please help me to write a regular expression for this purpose?

Best regargs, RussianRoot.

4

2 回答 2

0

If they all are delimited by + then why don't you use explode?

That will give you an array with each element and then you can do whatever you want with it.

A different way is to use str_replace and replace "ROSSO" with "COLOR_RED" and so on.

于 2013-04-15T08:27:01.677 回答
0

I don't think you need regex for this. Probably easier and faster to do something like:

$item = explode(' ', "NAPLAK ROSSO+S.ARG.+LACC.ARG.+NK");
$args = explode('+', $item[1]);
$item = $item[0];

echo $item;

Gives us "NAPLAK"

print_r($args);

Gives us:

array(4) [ 'ROSSO', 'S.ARG', 'LACC.ARG.', 'NK' ];
于 2013-04-15T08:45:59.660 回答