unique keyword in php which replace with defined variable -



unique keyword in php which replace with defined variable -

i want function in php replace unique word defined value. i.e

define("url","http://example.com"); define("website","stackoverflow"); $string = "this dummy text {url} & name of website {website}";

now want output as: dummy text http://example.com & name of website stackoverflow.

i have function work fine php 5.4

define("url","http://example.com"); define("website","stackoverflow"); function magickeyword($data) { $url = url; $sitename = website; homecoming preg_replace('/\{([a-z]+)\}/e', "$$1", $data); }

but in php 5.5 deprecated /e modifier.

deprecated: preg_replace(): /e modifier deprecated, utilize preg_replace_callback instead

now please help me.

the callback function used this:

define("url","http://example.com"); define("website","stackoverflow"); $string = "this dummy text {url} & name of website {website}"; function magickeyword($data) { homecoming preg_replace_callback('/\{([a-z]+)\}/', "magickeywordcallback", $data); } function magickeywordcallback($matches) { if (defined($matches[1])) homecoming constant($matches[1]); // otherwise homecoming found word unmodified. homecoming $matches[0]; } $result = magickeyword($string); var_dump($result);

result:

string(76) "this dummy text http://example.com & name of website stackoverflow"

php preg-replace deprecated

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -