Junior Spellweaver
- Joined
- Dec 29, 2015
- Messages
- 111
- Reaction score
- 75
Hey guys!
I want to replace all strings from a file and display it, but I don't know how I should replace the strings. That's my current code:
View.php (just a part)
If I do that:
I'll get an error, because I include the file, so I can't include just a text. What's the best way to change the values?
One of my language files (just a test):
I hope you can help me.
- Kylon
I want to replace all strings from a file and display it, but I don't know how I should replace the strings. That's my current code:
View.php (just a part)
Code:
public function languageParser() {
$lang = Config::get(['lang']);
$LangContent = (!file_exists(DS.'application/langs/'.$lang.'.json')) ? exit('Language File not found') : file_get_contents(DS.'application/langs/'.$lang.'.json');
$obj = json_decode($LangContent, true);
$file = file_get_contents($this->file);
foreach($obj as $o => $value) {
if(strpos($file, '{'. $o . '}') !== false) {
str_ireplace('{'. $o . '}', $value, $file);
}
}
}
If I do that:
Code:
public function languageParser() {
$lang = Config::get(['lang']);
$LangContent = (!file_exists(DS.'application/langs/'.$lang.'.json')) ? exit('Language File not found') : file_get_contents(DS.'application/langs/'.$lang.'.json');
$obj = json_decode($LangContent, true);
$file = file_get_contents($this->file);
foreach($obj as $o => $value) {
if(strpos($file, '{'. $o . '}') !== false) {
$this->file = str_ireplace('{'. $o . '}', $value, $file);
}
}
}
One of my language files (just a test):
Code:
{
"ME_PROFILE_TITLE" : "Mijn Profiel",
"SETTINGS_TITLE_GENERAL" : "TEST",
"SETTINGS_MOTTO_GENERAL" : "Motto",
"SETTINGS_MOTTO_DESCRIPTION_GENERAL" : "TEST111"
}
I hope you can help me.
- Kylon