我一直试图将3个字符串组合成一个并且无法这样做。
字符串在下面。
$from="/2/3/4/5/6/";
$to="/30/31/32/33/34/";
$sub="/2/3/4/5/6/7/8/9/10/11/12/";#this is dynamic, ever changing past > (/2/3/4/5/6/)
输出必须如下所示。
$output="/30/31/32/33/34/6/7/8/9/10/11/12/";
如果$sub
发生如下变化,则为
$from="/2/3/4/5/6/";
$to="/30/31/32/33/34/";
$sub="/2/3/4/5/6/7/8/";
$output="/30/31/32/33/34/6/7/8/";
如果$to
发生了变化,那么就这样。
$from="/2/3/4/5/6/";
$to="/30/31/";
$sub="/2/3/4/5/6/7/8/";
$output="/30/31/6/7/8/";
$to
需要先行,然后是最后的$sub
,减去结尾$from
之前的/*/(eg./6/)
要合并为1个字符串。
这怎么可能?
答案 0 :(得分:0)
您基本上存储在字符串内序列化的数组结构。聪明的Exploding应该有所帮助:
$output = $to
. implode('/', array_diff(
explode('/', $sub),
array_slice(explode('/', $from), 0, -2)
)) . '/';
替代方案可以是正则表达式
答案 1 :(得分:0)
这可能有助于您获得所需内容:
$str1 = substr($from, -2);
$pos = strpos($sub,$str1);
$str2 = substr($sub,$pos);
$output = $to.$str2;