在没有str_replace的情况下用下划线替换php字符串中的点

Har*_*vic 1 php

我有一个包含字符串的数组,其中一些字符串包含点('.').

我必须重复一遍.我不想用str_replace做这个.

所以,我需要用下划线替换那些点.

例如:

for($data as $key=>$value){
   print_r($value);
}
Run Code Online (Sandbox Code Playgroud)

让我们说输出如何:

'Hello. I have two dots. Please replace them!'
Run Code Online (Sandbox Code Playgroud)

我们希望得到的是:

'Hello_ I have two dots_ Please replace them!'
Run Code Online (Sandbox Code Playgroud)

提前致谢

Sha*_*rky 8

这是一个代码高尔夫还是什么?

无论如何,这是一个解决方案:

$text='Hello. I have two dots. Please replace them!';

echo IHateStrReplace(".","_",$text);

function IHateStrReplace($replace_from,$replace_to,$input)
{
    $result="";

    for($i=0;$i<strlen($input);$i++)
    {
        $result.= ($input[$i]==$replace_from)?$replace_to:$input[$i];
    }

    return $result;
} 
Run Code Online (Sandbox Code Playgroud)

http://3v4l.org/Cjp4G