如何用一个字符串中定义的字符替换某个字符使用PHP? [英] How to replace certain character with a defined character for it in a string using php?

查看:78
本文介绍了如何用一个字符串中定义的字符替换某个字符使用PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我可以用# 替换某个字符,如串。
我有一个数组中的所有字符检查器和替换器。像这样 -

  $ string_check = array(
#=># ,
....等等(列表太大)
);

那么我该如何做这件事。请帮助我。我只有20天的使用经验。

strtr()

  $ table = array(
'#'=>'...',
);
$ result = strtr($ source,$ table);


I have a question that can I replace a certain character like # with # in a string. I have all the character checkers and their replacer in an array. Like this--

$string_check = array(
                      "#" => "#",
                      .... and so on (list is too big)
                     );

So how can I do this thing. Please help me out. I only have 20 days of experience with php.

解决方案

You can feed your translation table right into strtr():

$table = array(
    '#' => '...',
);
$result = strtr($source, $table);

这篇关于如何用一个字符串中定义的字符替换某个字符使用PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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