我如何变量添加新的charcter另一个字符串?

时间:2016-01-08 09:58:38

标签: php variables

你好,你能帮助我,我的问题有时会变化。

<?php

$ns = "test";
echo $ns;

打印测试,但我不想要这个。

输出

  

T:E:s:t中

请帮帮忙?

3 个答案:

答案 0 :(得分:2)

使用chunk_split()

chunk_split()函数拆分函数。

在我们的例子中,它按每1个字符分割。

并添加一个新字符:

我们不需要上一个:字符,因此我们正在使用rtrim()

<?php
$ns = "test";
$n = chunk_split($ns, 1, ':');
echo rtrim($n, ":");
?>

Demo

答案 1 :(得分:1)

请尝试以下代码:

entry.nomZone.replace(/\s/g,'');

答案 2 :(得分:1)

 <?php $ns = "test";
    echo substr(chunk_split($ns, 1, ':'), 0, -1);
   ?>