php - Extract everything within brackets -


i have string of html tags inside saved in database e.g:

<p>hello {$name}, welcome {$shop_name}....</p> 

i want replace of tags real data, @ moment loop through available data , replace if exists.

foreach($data $key => $data){     $content = str_replace('{$'.$key.'}', $data, $content); } 

is there better way of doing without looping through of $data? growing on 5000 rows.

i mean possible extract variables {$name}/{$shop_name} replace on found?

you can single str_replace call.

$find = array(); $replace = array(); foreach($data $key => $data) {     $find[] = "\{$" . $key . "}";     $replace[] = $data; } $content = str_replace($find, $replace, $content); 

unless there real performance issue, wouldn't worry much.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -