内置函数在php中组合重叠的字符串序列? [英] built in function to combine overlapping string sequences in php?

查看:51
本文介绍了内置函数在php中组合重叠的字符串序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP 中是否有内置函数可以将 2 个字符串合并为 1 个?

Is there a built in function in PHP that would combine 2 strings into 1?

示例:

$string1 = 'abcde';
$string2 = 'cdefg';

组合得到:abcdefg.

如果确切的重叠序列和位置已知,则可以编写代码将它们合并.

If the exact overlapping sequence and the position are known, then it is possible to write a code to merge them.

TIA

推荐答案

可以使用 substr_replace()strcspn():

$string1 = 'abcde';
$string2 = 'cdefgh';

echo substr_replace($string1, $string2, strcspn($string1, $string2)); // abcdefgh

这篇关于内置函数在php中组合重叠的字符串序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆