0

我有一个类似的字符串[b] [e] [h] [k] [n] [q] [t],我想获取[a]并用类似的东西abc替换它并将其替换在同一位置。最后输出字符串必须像abc def ghi jkl mno pqr stu我该怎么做提前谢谢..

4

2 回答 2

0

尝试这个:

$output = str_replace("[a]", "abc", "[a][b] [e] [h] [k] [n] [q] [t]");

// out puts abc[b] [e] [h] [k] [n] [q] [t]
于 2013-06-05T10:54:42.070 回答
0

您可以使用str_replace

$string = "[a] [b] [e] [h] [k] [n] [q] [t]";

$search = array('[a]', '[b]', '[e]', '[h]', '[k]');
$replace = array('abc', 'bcd', 'efg', 'hij', 'klm');

$string = str_replace($search, $replace, $string);

echo $string

输出:

abc bcd efg hij klm [n] [q] [t]
于 2013-06-05T10:59:19.907 回答