CS174
Chris Pollett
May 2, 2016
We start today by finishing up our discussion of localization and internationalization begun last week.
gettext("translate_me"); // you could also use _("translate_me");
putenv('LC_ALL=en_US'); setlocale(LC_ALL, 'en_US'); // say locale bindtextdomain("myMoFile", "./locale"); // say locale dir textdomain("myMoFile"); // say .mo file _("translate_me"); // looks for ./locale/en_US/LC_MESSAGES/myMoFile.mo // to find the translation.
xgettext -L PHP filename.php
#: filename.php:6 msgid "translate_me" msgstr ""
msgfmt -o myMoFile.mo myMoFile.po
Which of the following statements is true?
<?php $blah++; ?>You should see a notice saying blah is undefined.
<php class Layout { public $view; function __contruct($view) { $this->view = $view; //contructor code } function render($data) { ?> <html> <head><title><?=$data['title']; ?></title></head> <body> <?php $this->view->render($data); ?> </body> </html> <?php } }This avoids headaches such as sending HTTP headers from a sessions after some HTML has been output.
echo $my_assoc['my_field']; //not echo $my_assoc[my_field];
http://www.cs.sjsu.edu/faculty/pollett/in this network, you used to be able to make a request to:
http://www.cs.sjsu.edu.nyud.net/faculty/pollett/i.e., I tack on .nyud.net to the domain name.
Array( "name" => "Bob", ..., "posts" => Array([0] => Array("title" => "Dark and Stormy Night", ...), [1]=>...))
pecl install Memcacheand then add the line
extension=memcache.so(or .dll on Windows) to your php.ini file and restart everything.
memcached -d -m 50 -l 127.0.0.1 -p 11211
telnet 127.0.0.1 11211 set foo 0 0 6 lalala STORED
VALUE key flags bytes\r\n data block\r\none for each value returned, followed by an END\r\n after the last value.
get foo VALUE foo 0 6 lalala END
$memcache = new Memcache();
$memcache->addServer($host, $port, $persistent, $weight, $timeout, $retry_interval);
$memcache->set($key, $val, $flag, $expire); // $flag is whether to compress the item in the store //$expire - Unix timestamp, or seconds from present. 0 -don't expire
$memcache->get($key);
<html> <head><title>Memcache Test</title></head> <body> <h1>Test</h1> <?php $memcache = new Memcache(); $memcache->addServer("localhost", 11211, true, 1, 1, 5); $memcache->set("bob", "value", null, 60); echo "<p>".$memcache->get("bob")."</p>"; ?> </body> </html>