ertui Posted December 28, 2008 Share Posted December 28, 2008 Hi, i don't understand where is the problem. <?php define('LANG_ESPANOL', "es"); define('LANG_ENGLISH', "en"); function language(){ $languages = ESPANOL; $languaje = substr($languages, 0, 1); return $language; } if (language() == "es") { echo "hablas espanol"; } elseif (language() == "en") { echo "you speak english"; } else { echo "unknow language"; } ?> Returns "unkow language", it shoudn´t be "hablas espanol" ?? Thanks! Link to comment https://forums.phpfreaks.com/topic/138668-problem-with-functions/ Share on other sites More sharing options...
carrotcake1029 Posted December 28, 2008 Share Posted December 28, 2008 define('LANG_ESPANOL', "es"); $languages = ESPANOL; Link to comment https://forums.phpfreaks.com/topic/138668-problem-with-functions/#findComment-725028 Share on other sites More sharing options...
ertui Posted December 29, 2008 Author Share Posted December 29, 2008 I still have the same problem... <?php define('LANG_ESPANOL', "es"); define('LANG_ENGLISH', "en"); function language(){ $languages = LANG_ESPANOL; $languaje = substr($languages, 0, 1); return $language; } if (language() == "es") { echo "hablas espanol"; } elseif (language() == "en") { echo "you speak english"; } else { echo "unknow language"; } ?> Link to comment https://forums.phpfreaks.com/topic/138668-problem-with-functions/#findComment-725098 Share on other sites More sharing options...
Mark Baker Posted December 29, 2008 Share Posted December 29, 2008 $languaje = substr($languages, 0, 1); ?? What's the point of this line? And are you really trying to get the first character of the language code, and so compare a single character against two characters.... and still expect them to match? Link to comment https://forums.phpfreaks.com/topic/138668-problem-with-functions/#findComment-725103 Share on other sites More sharing options...
ertui Posted December 29, 2008 Author Share Posted December 29, 2008 still same problem function language(){ $languages = espanol; $languaje = substr($languages, 0, 2); return $language; } Link to comment https://forums.phpfreaks.com/topic/138668-problem-with-functions/#findComment-725105 Share on other sites More sharing options...
HoTDaWg Posted December 29, 2008 Share Posted December 29, 2008 hello there i hope this can help you. <?php define('LANG_ESPANOL', "es"); define('LANG_ENGLISH', "en"); function language(){ $languages = espanol; $languaje = substr($languages, 0, 2); return $languaje; } if (language() == "es") { echo "hablas espanol"; } elseif (language() == "en") { echo "you speak english"; } else { echo "unknow language"; } ?> Link to comment https://forums.phpfreaks.com/topic/138668-problem-with-functions/#findComment-725116 Share on other sites More sharing options...
vividona Posted December 29, 2008 Share Posted December 29, 2008 <?php define('LANG_ESPANOL', "es"); define('LANG_ENGLISH', "en"); function language(){ $languages = ESPANOL; $languaje = substr($languages, 0, 1); return $language; } if (language() == LANG_ESPANOL) { echo "hablas espanol"; } elseif (language() == LANG_ENGLISH) { echo "you speak english"; } else { echo "unknow language"; } ?> Link to comment https://forums.phpfreaks.com/topic/138668-problem-with-functions/#findComment-725311 Share on other sites More sharing options...
ertui Posted December 29, 2008 Author Share Posted December 29, 2008 it finally works!! <?php define('LANG_ESPANOL', "es"); define('LANG_ENGLISH', "en"); function language(){ $languages = espanol; $languaje = substr($languages, 0, 2); return $languaje; } if (language() == LANG_ESPANOL) { echo "hablas espanol"; } elseif (language() == LANG_ENGLISH) { echo "you speak english"; } else { echo "unknow language"; } ?> Thanks a lot!! Link to comment https://forums.phpfreaks.com/topic/138668-problem-with-functions/#findComment-725339 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.