首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >str_replace()不能使用"(“和"[”PHP

问str_replace()不能使用"(“和"[”PHP
EN

Stack Overflow用户
提问于 2018-04-25 11:48:29
回答 1查看 60关注 0票数 0

这是我用php编写的简单代码函数

代码语言:javascript
复制
function replaceCharact($input,$action){
    $output_1 = str_replace('(', "%11%", $input);
    $output_2 = str_replace(')', '%12%', $output_1);
    $output_3 = str_replace('[', '%13%', $output_2);
    $output_4 = str_replace(']', '%14%', $output_3);
    $output_5 = str_replace('"', '%15%', $output_4);
    $output_6 = str_replace('/', '%16%', $output_5);
    $output_7 = str_replace('"\"', '%17%', $output_6);
    $output_8 = str_replace('!', '%18%', $output_7);
    $output_9 = str_replace('<', '%19%', $output_8);
    $output_10 = str_replace('>', '%20%', $output_9);
    return $output_10;    
}

仅"!"($output_8)更改为%19%。其他输出不显示任何内容。你能帮我做这个吗?

EN

回答 1

Stack Overflow用户

发布于 2018-04-25 12:39:16

要使用数组简化批量替换,请尝试以下操作...

代码语言:javascript
复制
$replacement = array(
  '(' => "%11%",
  ')' => '%12%',
  '[' => '%13%',
  ']' => '%14%'
  // etc etc
);

$string = str_replace( array_keys( $replacement ), $replacement, $string );

https://3v4l.org/kmXZp

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50013772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档