nafetski Posted November 1, 2007 Share Posted November 1, 2007 Hey everybody, time for a stupid question Here is the scenario... Our website has a spanish and english version, the data for both languages are pulled using an arrays of arrays. I have one file that contains all of the arrays, here is an example of one $products = array{ "dirtbike"=>array("dirtbike_eng","dirtbike_sp"), } A session variable is set (0 for English, 1 for Spanish) and the appropiate translation is pulled out of the array based on that. It works great, easy to update and change things on our site...but now we want to take the task of translating and updating the page out of the hands of our web designer (me) and let operations do it. They want a simple text file that they can edit and just upload to the web server for the changes to take effect...here is an example of what I have given them (translation.txt) ID ------ English ----- Spanish dirtbike | dirtbike_eng | dirtbike_sp I can read the translation.txt file fine using $data=file(translation.txt); Now it puts each line into an array. What I want to do, is use explode on each line (using a ' | ' delimiter) and output each line into it's own array of arrays. Here is what I have so far <?php $data=file(translation.txt); $explodedata=explode(' | ', $data); var_dump($explodedata); ?> The $explodedata array has no values! ;( I'm pretty sure I'm just using completely wrong logic. Anybody mind pointing me in the right direction? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/75671-solved-using-explode-on-an-array/ Share on other sites More sharing options...
wildteen88 Posted November 1, 2007 Share Posted November 1, 2007 That is because $data is an array and explode will only work on strings. You will need to loop through the $data array, eg: $translations= file('translation.txt'); foreach($translations as $translation) { list($id, $english, $spanish) = explode(' | ', $translation); $translate[$id][0] = $english; $translate[$id][1] = $spanish; } echo '<pre>', print_r($translate, true), '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/75671-solved-using-explode-on-an-array/#findComment-382919 Share on other sites More sharing options...
nafetski Posted November 1, 2007 Author Share Posted November 1, 2007 Works great. You are amazing. Seriously, thanks so much for taking time out of your day to respond (and so fast!)- this just saved me such a big headache. So appreciated. Thank you, thank you, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/75671-solved-using-explode-on-an-array/#findComment-382921 Share on other sites More sharing options...
wildteen88 Posted November 1, 2007 Share Posted November 1, 2007 No problem. Glad I could help! Quote Link to comment https://forums.phpfreaks.com/topic/75671-solved-using-explode-on-an-array/#findComment-382923 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.