On Sat, 21 Aug 2004 12:54:15 -0500, Shawn McKenzie <[EMAIL PROTECTED]> wrote: > Turbo wrote: > > Hi, > > > > I have array variable and string variable. > > I want to replace value of array by key of array in string variable > > with preg_replace(). > > > > Example : > > $message=array( > > 'name'=>'My Computer', > > 'version'=>'1.0' > > ); > > $strValue="I am $name,build version $version\n"; > > > > How's to replace?
You could just change your string to be: $strValue = 'I am '.$message['name'].',build version '.$message['version']."\n"; or $output = preg_replace('/\$([A-Z_\-0-9]*)/ie', '$message["$1"]', $strValue); This is not quite a complete solution and may not work (is not tested). > > > > Yingyos > > Why preg_replace? > > Just do extract($message); then you have vars from the keys: > > $name ='My Computer'; > and > $version = '1.0'; > > Then those vars are used in the $strValue var. > -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php