Q:

write file with define constant having error to not put his value

below is my code, i need to write URL value in file with define path. but it output as URL and not replace with his define value, $string variable value cone from database.
<?php
define("URL","http://example.com/mail.php");
$string = 'Page here : {{URL}}'; // string come from database using query //
//$string = str_replace("{{","'.",$string);
//$string = str_replace("}}",".'",$string);

$f = fopen("d:\abc1.txt",'w');
$wr = fwrite($f,$string);
fclose($f);
?>

output in file was : Page here : {{URL}}
but i need something like this : Page here : {{http://example.com/mail.php}}
i also try using comment line to replace string and get out URL into string. 

A:

Well, if I get it right, you have a dynamic string from DB, which somewhere contents this: '{{URL}}'. So just do simple replace like this:
define("URL","http://example.com/mail.php");
$string = str_replace('{{URL}}', '{{' . URL . '}}', $string);

This replaces URL text using URL value of that constant

