以这些字符串为例:
<?php
$strOne = "Place new content here: , but not past the commma.";
$strTwo = "test content";
?>
因此,根据上面的字符串,如何制作一个新的字符串,如下所示:
<?php
$finalstr = "Place new content here: test content, but not past the comma.";
?>
编辑
另外,假设我没有访问$ strOne的权限,这意味着我想通过字符串函数而不是通过污染等直接对字符串进行修改...
尝试的组合strpos
和substr_replace
?
$strOne = "Place new content here: , but not past the commma.";
$strTwo = "test content";
// find the position of comma first
$pos = strpos($strOne, ',');
if ($pos !== false)
{
// insert the new string at the position of the comma
$newstr = substr_replace($strOne, $strTwo, $pos, 0);
var_dump($newstr);
}
输出:
string(63)“在此处放置新内容:测试内容,但不要超过逗号。”
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句