0

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.

1

2 Answers 2

3
str_replace("{num}", $id, $format);
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.