华域联盟 PHP 如何替换php中的字符串

如何替换php中的字符串

我想替换 \\'<\\' 和 \\'>\\' 登录字符串。
例如

1
2
3
$str = 'if x<y and y>z' ;
echo str_replace ( '<' , 'something' , $str ) . "\
"
;

这给出以下结果

1 if xsomethingy and y >z

我的问题是如何将 \\'>\\' 替换为文本 \\'something\\'


1 str_replace ( array ( '<' , '>' ) , 'something' , $str )

有可能,见手册



相关讨论

  • 我应该如何将 \\'>\\' 替换为其他文本而不是具体 \\'something\\'
  • 和 \\'<\\' 应该替换为 \\'something\\'
  • 感谢 RC 我已经通过使用 str_replace(array(\\'<\\',\\'>\\'),array(\\'


签出 preg_replace()

文档在这里 http://php.net/manual/en/function.preg-replace.php

例子是
preg_replace('/[<>]/', 'something', $str);


preg_replace(/[<>]/g, 'something', $str)

你需要学习一些 PHP 呀
http://php.net/manual/en/function.preg-replace.php


本文由 华域联盟 原创撰写:华域联盟 » 如何替换php中的字符串

转载请保留出处和原文链接:https://www.cnhackhy.com/158225.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部