emehrkay Posted March 17, 2007 Share Posted March 17, 2007 say i have an array $var = array('name' => 'mark', 'city' => 'some city'); ...etc and i have a block of text "Hi <[name]>, do you live in <[city]>?" how should i efficiently replace the <[]> vars with their matching key vals in my array? thanks Link to comment https://forums.phpfreaks.com/topic/43148-solved-string-replace-help/ Share on other sites More sharing options...
suzzane2020 Posted March 17, 2007 Share Posted March 17, 2007 hi, If i got ur question rite , you cud use the foreach array function Link to comment https://forums.phpfreaks.com/topic/43148-solved-string-replace-help/#findComment-209544 Share on other sites More sharing options...
emehrkay Posted March 17, 2007 Author Share Posted March 17, 2007 Thanks suzzanne, I actually figured it out. while creating my $val array, i create a replace_val array and just do str_replace <?php foreach($arr as $key => $val){ if($key == 'email_id'){ $this->_email_id = $val; }else{ $this->_vars[$key] = $val; $this->_replace_vars[] = '<['. $key .']>'; } } private function buildEmail(){ $email = emailSQL::getEmailText($this->_email_id); return str_replace($this->_replace_vars, $this->_vars, $email); } ?> i just hope that it works Link to comment https://forums.phpfreaks.com/topic/43148-solved-string-replace-help/#findComment-209550 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.