简体   繁体   中英

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 retrive some string from user wich 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 kinda like templating engine.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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