[英]how to replace a string in php
我想在字符串中替换“<”和“>”符号。 例如
$str = 'if x<y and y>z'; echo str_replace( '<', 'something', $str ) . "\n";
这给出了以下结果
if xsomethingy and y>z
我的问题是如何将'>'替换为'some something'
str_replace( array('<', '>'), 'something', $str )
有可能,请参见手册
preg_replace(/[<>]/g, 'something', $str)
您需要学习一些PHP知识
http://php.net/manual/en/function.preg-replace.php
退房preg_replace()
文档在http://php.net/manual/en/function.preg-replace.php
例如preg_replace('/[<>]/', 'something', $str);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.