Muhammad Ali Hassan
Muhammad Ali Hassan

Reputation: 962

how can we add and replace tags in php

i want insert tags in my string. which can be replaced later. for e.g.

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

is there any way to do this. Thanks.

Upvotes: 0

Views: 49

Answers (1)

Raggamuffin
Raggamuffin

Reputation: 1760

use 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;

Upvotes: 2

Related Questions