Ariona Rian
Ariona Rian

Reputation: 9437

Replacing string with some variable

I am not an expert with Regular Expression, so maybe this question has some basic implementation of regex.

First I have retrieve some string from user which has a format like this:

$id =3;
$format = {num}/sometext/sometext;

The question is how to replace {num} with the variable of id, so the result will be :

3/sometext/sometext;

it's kind of like a templating engine.

Upvotes: 0

Views: 60

Answers (2)

scottlimmer
scottlimmer

Reputation: 2278

Couldn't you just use str_replace('{num}', $id, $format); ?

Upvotes: 0

Orangepill
Orangepill

Reputation: 24645

str_replace("{num}", $id, $format);

Upvotes: 3

Related Questions