davidolson Posted November 14, 2014 Share Posted November 14, 2014 (edited) How should i input language file into db and then output it with user selected language? $username = 'KELLY'; $offerName = 'Crowd Flower'; $amount = '30'; $currency = 'points'; $lang['text']['a_001'] = '%a has just completed the %b offer worth %c %d.';// ENGLISH // $input = str_replace(array('%a','%b','%c','%d'), array($username, $offerName, $amount, $currency), $lang['text']['a_001']); print $input; Edited November 14, 2014 by davidolson Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 14, 2014 Share Posted November 14, 2014 If it is a file, why do you need to store it in the database? If you are going to store in the DB, then you would want to store the data in separate fields for username, offername, etc. Quote Link to comment Share on other sites More sharing options...
davidolson Posted November 14, 2014 Author Share Posted November 14, 2014 db SCHEMA happening_now ------->id->message->dateCreated function insertHappening($message, $date, $db){ $query = 'INSERT INTO happening_now (message, dateCreated) VALUES (:message, :dateCreated)'; $insert = $db->prepare($query); $insert->bindValue(':message', $message, PDO::PARAM_STR); $insert->bindParam(':dateCreated', $date, PDO::PARAM_INT); $success = $insert->execute(); if($success){ return TRUE; } return FALSE; } function showHappening($db, $limit = 20){ $query = 'SELECT * FROM happening_now ORDER BY dateCreated DESC LIMIT :limit'; $select = $db->prepare($query); $select->bindParam(':limit', $limit, PDO::PARAM_INT); $select->execute(); if(!empty($select->rowCount())){ while($row = $select->fetch(PDO::FETCH_ASSOC)){ print ' <div>'.timeAgo('@'.$row['dateCreated']).' - '.$row['message'].'</div><br>'; } } } function timeAgo($dateFrom, $dateTo = NULL){ $dateStart = date_create($dateFrom); if($dateTo === NULL){ $dateEnd = date_create(NULL); }else{ $dateEnd = date_create($dateTo); } $interval = date_diff($dateStart, $dateEnd); $doPlural = function($nb, $str){return $nb > '1' ? $str.'s' :$str;}; // adds plurals $format = array(); if($interval->y !== 0){ $format[] = '%y '.$doPlural($interval->y, 'year'); } if($interval->m !== 0){ $format[] = '%m '.$doPlural($interval->m, 'month'); } if($interval->d !== 0){ $format[] = '%d '.$doPlural($interval->d, 'day'); } if($interval->h !== 0){ $format[] = '%h '.$doPlural($interval->h, 'hour'); } if($interval->i !== 0){ $format[] = '%i '.$doPlural($interval->i, 'minute'); } if($interval->s !== 0){ $format[] = '%s '.$doPlural($interval->s, 'second'); } if(count($format) > 1){ $format = array_shift($format).' and '.array_shift($format); }else{ $format = array_pop($format); } return $interval->format( $format.' ago'); } $username = 'KELLY'; $offerName = 'Crowd Flower'; $amount = '30'; $currency = 'points'; $lang['text']['a_001'] = '%a has just completed the %b offer worth %c %d.';// language/english/user.php // insertHappening(str_replace(array('%a','%b','%c','%d'), array($username, $offerName, $amount, $currency), $lang['text']['a_001']), createUnixTimestamp($configs), $db); showHappening($db, 15);// Show output based on user selected language // // OUTPUT // //46 minutes ago - KELLY has just joined our community. //19 minutes and 5 seconds ago - KELLY has just completed the Crowd Flower offer worth 30 points. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.