PHP Tips and Tricks
PHP Tips and Tricks. LCA 2004. Jan.14, 2004. Adelaide. Rasmus Lerdorf rasmus@php.netgt; … server-side and all PHP tags will be replaced by the server before …
More PDF Content
PHP Tips and Tricks PHP Tips and Tricks
LCA 2004 Jan.14, 2004. Adelaide Rasmus Lerdorf http://lerdorf.com/lca04.pdf Slide 1/62 January 13 2004 Many Things PHP is Many Things to Many People o The BASIC of the Web o Web Template System o General-purpose Scripting Language o Advanced Application Framework o Application Server? – 2 – Slide 2/62 January 13 2004 Template System o A mechanism to separate logic from layout. o The defining characteristic is where and how the intersection between logic and layout is done. o PHP is a general-purpose templating system. o Any general-purpose templating system will eventually become PHP. – 3 – Slide 3/62 January 13 2004 PHP is Big! January 2004 Netcraft Report o 46,067,743 Domains queried o 14,699,098 Domains. 1,330,821 IP addresses o PHP installed on 32% of all domains Source: Netcraft January 2004 Apache Module Report o 9,286,904 Apache Servers surveyed o 5,010,035 (53.95%) PHP o 2,608,258 (28.09%) OpenSSL o 2,527,385 (27.21%) mod_ssl o 1,845,621 (19.87%) Frontpage o 1,597,830 (17.21%) mod_perl o 411,443 (4.43%) DAV o 380,012 (4.09%) mod_throttle o 360,440 (3.88%) mod_log_bytes o 355,235 (3.83%) mod_bwlimited o 327,263 (3.52%) mod_jk o 233,404 (2.51%) mod_fastcgi o 222,410 (2.39%) AuthMySQL Source: SecuritySpace.com – 4 – Slide 4/62 January 13 2004 Killer Apps! Thousands of cool PHP apps out there. Some better than others. Here are some I use: o Gallery – http://gallery.menalto.com/ o SquirrelMail – http://squirrelmail.org o FudForum – http://fud.prohost.org/ o Serendipity – http://s9y.org/ o Cacti – http://www.raxnet.net/products/cacti/ – 5 – Slide 5/62 January 13 2004 Server-Side PHP is a Server-side language Even though it is embedded in HTML files much like the client-side Javascript language, PHP isserver-side and all PHP tags will be replaced by the server before anything is sent to the webbrowser. So if the HTML file contains: What the end user would see with a “view source” in the browser would be: Hello World – 6 – Slide 6/62 January 13 2004 Embedding PHP The 4 available tag styles
<= ‘ASP Tags’ >
Output: Short Tags – Most commonLong Tags – PortableASP TagsReally Long Tags – rarely used – 7 – Slide 7/62 January 13 2004 gdchart gdchart is a fast graphing extension written entirely in C. It can handle most common types ofgraphs with the only major missing feature being that it currently doesn’t handle legends. Eithercreate your own legend beside your graph, or maybe even layer it into the background image ofyour gdchart graph if you have a static legend. Line Chart add(array(2.5, 5.1, 8.6, 12.0, 15, 9, 8, 7)); $chart->add(array(5.0, 8.0, 9.2, 10.2, 7, 8, 10, 9)); $chart->add(array(8.0, 10.0, 14.0, 18.2, 16, 14, 12, 10)); $chart->labels = array(”Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”, “Aug”); $chart->colors = array(0×1133aa, 0xaa3311, 0×33aa11); $chart->out(640,480,IMG_PNG);?> Output: Line Chart with custom axes add(array(2.5, 5.1, 8.6, 12.0, 15, 9, 8, 7)); $chart->add(array(5.0, 8.0, 9.2, 10.2, 7, 8, 10, 9)); $chart->add(array(8.0, 10.0, 14.0, 18.2, 16, 14, 12, 10)); $chart->labels = array(”Jan”,”Feb”,”Mar”,”Apr”,”May”,”Jun”,”Jul”, “Aug”); $chart->requested_ymin = 0; $chart->ylabel_density = 25; $chart->ylabel_fmt = “%.0f”; $chart->colors = array(0×001133aa, 0×00aa3311, 0×33aa11); $chart->out(640,480,IMG_PNG);?> Output: – 8 – 3D Area Chart depth = 5; $chart->xtitle = “Fruits”; $chart->xtitle_color = 0xffff00; $chart->bg_color = 0×112233; $chart->xlabel_color = 0xffffff; $chart->ylabel_color = 0xffffff; $chart->colors = array(0×30ffff00, 0×30ff00ff, 0×3000ffff); $chart->add(array(2.5, 5.1, 8.6, 12.0)); $chart->add(array(5.0, 8.0, 9.2, 10.2)); $chart->add(array(8.0, 10.0, 14.0, 18.2)); $chart->labels = array(”Apples”,”Oranges”,”Melons”,”Pears”); $chart->out(640,480,IMG_PNG);?> Output: – 9 – Pie Chart title = “This is a Sample Pie Chart”; $chart->title_font = “/usr/share/fonts/truetype/CANDY.ttf “; $chart->title_ptsize = 24; $chart->label_font = “/usr/share/fonts/truetype/Jester.ttf”; $chart->label_ptsize = 16; $chart->edge_color = 0×000000; $chart->labels = array(”red”,”green\r\n(exploded)”, “lt blue”,”purple”,”missing”,”cyan”,”blue”); $chart->add(array(12.5, 20.1, 2.0, 22.0, 5.0, 18.0, 13.0)); $chart->missing = array(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE); $chart->explode = array(0,40,0,0,0,0,0); $chart->pie_depth = 30; $chart->perspective = 0; $chart->pie_angle = 90; $chart->label_line = false; $chart->percent_labels = LABEL_ABOVE; $chart->out(640,480,IMG_PNG);?> Output: – 10 – Combo High-Low-Close Chart title = “High-Low-Close On top of an Area(volume) Graph”; $chart->depth = 5.0; $chart->angle = 50; $chart->annotation_font_size = FONT_TINY; $chart->anno_note = “Earnings\nReport”; $chart->anno_point = 8; $chart->vol_color = 0×40806040; $chart->grid = TICK_LABELS; $chart->ylabel_density = 40; $chart->hlc_style = HLC_CONNECTING | HLC_I_CAP | HLC_DIAMOND; $chart->add_scatter(17.0, 3, SCATTER_TRIANGLE_UP, 0×50808060, 30); $chart->add(array(17.8,17.1,17.3,17.2,17.1,17.3,17.3,17.3,17.1,17.5,17.4)); $chart->add(array(16.4,16.0,15.7,15.25,16.0,16.1,16.8,16.5,16.8,16.2,16.0)); $chart->add(array(17.0,16.8,16.9,15.9,16.8,17.2,16.8,17.0,16.9,16.4,16.1)); $chart->add_combo( array(150.0,100.0,340.0,999.0,390.0,420.0,150.0,100.0,340.0,1590.0,700.0)); $chart->labels =array(”May”,”Jun”,”Jul”,”Aug”,”Sep”,”Oct”,”Nov”,”Dec”,”Jan”,”Feb”,”Mar”,”Apr”); $chart->out(640,480,IMG_PNG);?> Output: – 11 – – 12 – Slide 8/62 January 13 2004 PDFs on-the-fly A PDF Invoice $sizes = array(’a4′=>’595×842′, ‘letter’=>’612×792′, ‘legal’=>’612×1008′); if(!isset($type)) $type=’letter’;list($x,$y) = explode(’x',$sizes[$type]); $items = array(array(’Our special low-cost widget that doeseverything’,'299.99′), array(’Our
Processing your request, Please wait....