1

我整天都在试图解决这个问题,但我怎样才能可靠地按以下顺序拆分下一行。

被动:标记与附近盟友隔离的敌人。主动:造成 70/100/130/160/190 (+) 点物理伤害。如果目标被孤立,数量会增加到 100/145/190/235/280 (+)。进化的大爪:对孤立的敌人造成的伤害增加其已损失生命值的 12/12/12/12/12%(对怪物最大 200/200/200/200/200)。将尝尝恐惧的范围和卡兹克的基本攻击范围扩大 50/50/50/50/50。

Array
(
    [0] =>  Array
        (
            [0] => Passive
            [1] => Marks enemies who are isolated from nearby allies.
        )
    [1] =>  Array
        (
            [0] => Active
            [1] => Deals 70/100/130/160/190 (+) physical damage. If the target is isolated, the amount is increased to 100/145/190/235/280 (+).
        )
    [2] =>  Array
        (
            [0] => Evolved Enlarged Claws   
            [1] => Increases damage to isolated enemies by 12/12/12/12/12% of their missing health (max 200/200/200/200/200 vs. monsters). Increases the range of Taste Their Fear and Kha'Zix's basic attacks by 50/50/50/50/50.
        )
)

我不能超过中间的句子。

4

3 回答 3

2
(?:^|\s*)([^.:]+):\s*(.+?\.)(?=[\w\s]+:|$)

名称在捕获组 1 中,描述在捕获组 2 中

于 2012-09-27T16:19:48.723 回答
1

好吧,这似乎可以解决问题...

preg_match_all('/(?<=^|[.] )([^:]+): (.+?[.])(?=[^.]+:|$)/', $text, $matches, PREG_SET_ORDER);
var_dump($matches);

...如果我理解给定的结构('Term: Description. Term: Description'等)。实际上,描述中的冒号可能会破坏它;点在这里做得很好。

这个匹配的结果可以很容易地转换成一个关联数组:

$spell = array();
foreach ($matches as $match) {
   $spell[$match[1]] = $match[2];
}
于 2012-09-27T16:04:39.290 回答
0

用作.父/主数组和:子数组的分隔符。

function so12625378_explode_to_multiarray( $string )
{
    foreach ( explode( ". ", $your_string ) as $part )
        $result[] = explode( ": ", $part );

    return $result;
}

采用:

 $string = 'Passive: Marks enemies who are isolated from nearby allies. Active: Deals 70/100/130/160/190 (+) physical damage. If the target is isolated, the amount is increased to 100/145/190/235/280 (+).';
 echo '<pre>'.var_export( so12625378_explode_to_multiarray( $string ), true ).'</pre>';
于 2012-09-27T16:12:39.353 回答