PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
When I call the view helper's getCountryName('us') it doesn't return anything. No errors or anything. I'm loading the countries from a file that looks like this:
<?php
class Redeemed_View_Helper_GetCountryName extends Zend_View_Helper_Abstract
{
public function getCountryName($code)
{
return Redeemed_Countries::getInstance()->getCountryName($code);
}
}
I had an error in the function that loads the list. if(!$file) didn't have anything after it. So I put die('cant load countries.txt'); Now instead of displaying the page, PHP stops working and displays a white page. No errors or anything.
Okay I did some poking around, the problem is that I was using fread instead of fgets. Unfortuantly now, it returns the error 'undefined index: US'. Here is what print_r on the array returns.
Ugh. Okay after enough poking around and pulling my hair out, the problem was the country codes had a newline character due to being at the end of each line in the file. So I solved the problem by trim()ing the codes.
I guess the question now is: is there any benefit to putting this in a text file instead of the DB? I did it because I figured it would save some resources by not having to query the db.