简体   繁体   English

我们如何在php中添加和替换标签

[英]how can we add and replace tags in php

i want insert tags in my string. 我想在我的字符串中插入标签。 which can be replaced later. 可以在以后更换。 for eg 例如

$msg = "This message was sent [tag replaced later] at []";

is there any way to do this. 有没有办法做到这一点。 Thanks. 谢谢。

use str_replace.. 使用str_replace ..

$tags = array(
 '[a_tag]',
 '[another_tag]'
);
$replacements = array(
  'replace a tag',
  'replace another tag'
);

$string = 'I want to [a_tag] and [another_tag]';
$string = str_replace($tags, $replacements,$string);

echo $string;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM