TOOLBOX 2.2 Jean-Christophe (JC) Nebel j.nebel@kingston.ac.uk http://staffnet.kingston.ac.uk/~ku33185
Interested in starting up in business and/or developing enterprise skills Join the Enterprising Business Award scheme Enterprising Business Awards (Handbook) available on studentspace http://www.kingston.ac.uk/services-forbusiness/entrepreneurship/registration/ -Receive expert mentoring from the Entrepreneurship Team and our resident entrepreneur Simon Hulme, successful in business and now an Angel Investor. - There is the opportunity to receive financial support to get your idea, project or career off the ground. Presentation: Thursday 23 rd February 2pm http://www.youtube.com/watch?v=iswzu366qz0&feature=youtu.be
Activity 1.1: feedback Completions: 75! extremely poor Last year: ~200!
Activity 1.1: feedback Most people found the activity quite straight forward forgot to close tags did some research to find right syntax: including images or embedding videos (<embed >, not <a href >) -> Lecture video, http://www.w3schools.com, online tutorials
Activity 1.1: feedback How to deal with special characters? Why some headers smaller than text in Spring CSS?
Activity 1.1: feedback Interesting to see the different ways different browsers reacted to CSS style sheets Problem with list numbers http://msdn.microsoft.com/en-us/library/cc351024(v=vs.85).aspx http://www.w3schools.com/html/html_lists.asp Where can I change the background colour? see spring.css Is it possible to get a web development software for free, which is as good as CS5 Adobe Dreamweaver?
Activity 1.1: feedback About screen copy and image scaling (e.g. http://www.irfanview.com/) I tried to capture my webpage, but I got only a black screenshot for the video part The problem is usually due to graphics hardware acceleration being used to display the image: A solution is to disable the hardware acceleration (Control Panel) Image formats in html:.gif,.jpg,.jpeg,.bmp,.png
Activity 1.1: feedback Please if you can explain more about how to link the style and the exact code that we need to write as I didn't get it that much Here only link 1 CSS at a time, but LINK to several CSS is possible I didn't understand about what does 'minimal me' mean? How to centre a picture? : CSS, http://www.w3.org/style/examples/007/center.en.html Your mark is not affected by your question(s)
Activity 1.2: feedback Completions: 66! extremely poor Last year: ~150!
Activity 1.2: feedback Those who tried succeeded! -> Trial and error -> W3schools website + google + lecture video. Wordpad much better than Notepad (formatting) Some browsers do not handle well wobbly scripting vs programming languages JAVA applets <APPLET code="helloworld.class" WIDTH="200" HEIGHT="40"> This is where the aplet runs.</applet> Anchors?
Activity 1.2: feedback how to link two css together to html? LINK twice, however here I want you to merge the 2 files wobbly-spring style When I was creating my page to put a background colour was simply just background but when I went onto the help site I noticed they do background-color: does both these ways work? Colours? Predefined names (147) or RGB values background-color:#ff0000; background-color:red;
TOOLBOX 2.2 Jean-Christophe (JC) Nebel j.nebel@kingston.ac.uk http://staffnet.kingston.ac.uk/~ku33185
History Started as a Perl hack in 1994 by Rasmus Lerdorf (to maintain his homepage): "Personal Home Page Tools PHP Tools v1.0: released publicly - to accelerate bug location and improve the code - in 1995. Currently PHP v5.3: PHP Hypertext Preprocessor Free to download (open source): http://www.php.net/ PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) PHP runs on Windows, Linux, Unix and Mac OSX. PHP is compatible with most servers, e.g. Apache & IIS
Usage (Dec 2010) PHP is a good example of a successful open source project: very widely used for websites Has a lot of community support http://phpadvent.org/2010/usage-statistics-by-ilia-alshanetsky
Features Procedural language: functions Syntax similar to C/C++ or Java: if (cond) {..} else { }, while (cond) {.. }, for(startcond; inc; endcond) { } Extensive Function Library Not fully object-oriented - classes are additional Hacky: developed by hackers Good Web-server integration Script embedded in HTML Easy access to form data and output of HTML pages Run-time interpreted by the web server
PHP and HTML HTML-embedded PHP scripts are essentially HTML pages with occasional sections of PHP script. PHP script is enclosed in tag pairs: <p> Today's day: <?php print date("l")?> <p> Today's date: <?php print date('l js \of F Y h:i:s A')?> stringdate(string$format[,int$timestamp= time()] ) http://php.net/manual/en/function.date.php
PHP (Client-server) Client side Server side.html,.css PHPembedded in an HTML file.html,.css,.php
Website template Create a file called header.php which will have the header HTML code. You can use FrontPage/Dreamweaver to create the header, but remember to remove the closing </BODY> and </HTML> tags. <html> <head> <title> My website</title> <link rel="stylesheet" type="text/css" href= mycssfile.css"> </head> <body> --- my cool header here Create a file called footer.php which will have the footer HTML code. --- my cool footer here </body> </html>
Website template This is the basic template that you will use on all of the pages. Make sure you name the files with a.php extension so that the server will process the PHP code. Here, we assume the header and footer files are located in the same directory. <?php?> // header include( header.php ); Insert content here! <?php?> // footer include( footer.php );
Website template Benefits: - Any changes to header or footer only require editing of a single file. - Helps separate the content and design This reduces the amount of work necessary for site maintenance and redesign. Header Page 1 Content Page 2 Content Page 3 Content Page 4 Content Page 5 Content Footer
Function library Basic tasks String Handling Mathematics random numbers, trig functions.. Regular Expressions Date and time handling File Input and Output And more specific functions for- Many are obvious to c programmers: strlen, printf, fprintf, strpos Database interaction: MySQL, Oracle, Postgres, Sybase, MSSQL... Encryption Text translation Spell-checking Image creation XML Hacky : addcslashes, explode, soundex, quotemeta http://www.php.net/manual/en/funcref.php
Variables In PHP, a variable does not need to be declared PHP automatically converts the variable to the correct data type, depending on its value. Variables start with $ Example: <?php $mydateofbirth=1980; $thisyear=date("y"); $myage= $thisyear-$mydateofbirth; if($myage"]>30) echo "You are not that young..."; else echo "You are still young.";?>
PHP Form handling HTML form with two input fields & a submit button: <html> <body> <form action="useformpost.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> When a user fills out the form above and click on the submit button, the form data is sent to a PHP file, called "useformpost.php.
PHP Form handling useformpost.php: recover inputs and use them <html> <body> Welcome <?php echo $_POST["fname"];?>!<br /> You are <?php echo $_POST["age"];?> years old. <?php $thisyear=date("y")?><br/> You were born in <?php echo $thisyear-$_post["age"];?>!<br/> <?php if($_post["age"]>30) echo "You are not that young..."; else echo "You are still young.";?> </body> </html>
PHP Form handling In PHP, there are 2 modes to send and retrieve information from forms: GET & POST <form action="useformpost.php method="post"> <?php echo $_POST["fname"];?> or <form action="useformget.php method= get"> <?php echo $_GET["fname"];?> Information sent with GET is visible to everyone (in the browser's address bar) & has a size limit (2000 characters): - DO NOT use when sending passwords or sensitive data! - URL can be bookmarked: /useformget.php?fname=jc&age=32 Information sent with POST is invisible & has no size limit
Example of File handling: web counter How to count how many times your webpage has been accessed? <?php $COUNTER_FILE = webcounter.txt"; if (file_exists($counter_file)) { $fp = fopen("$counter_file", "r+"); $hits = fread($fp, 1024); rewind($fp); $hits += 1; fwrite($fp, $hits); fclose($fp); echo "You are visitor $hits"; } else { echo "counter is not available"; }?> File with correct rights Return boolean value (TRUE or FALSE) File opening modes
Use of PHP with Databases PHP is compatible with many databases: MySQL, Oracle, Postgres, Sybase, MSSQL... We will study databases in a future lecture
Use MySQLwith PHP We can simply use PHP functions and mysql queries together: Connect to the database server and login (this is the PHP command to do so) mysql_connect("host","username","password"); Choose the database mysql_select_db("database"); Send SQL queries to the server to add, delete, and modify data mysql_query("query"); Close the connection to the database server (to ensure the information is stored properly) mysql_close();
PHP resources PHP Download http://www.php.net/ PHP Tutorial http://www.w3schools.com/php/default.asp PHP Programmers http://www.phpide.de/ Programmer's text editor (syntax highlighting for PHP ): JEdit http://www.jedit.org/ Hotscripts A large number of PHP scripts (15000+) can be found at: http://www.hotscripts.com/category/scripts/php/
Activity 2.2 - Create a webpage which allows converting units from the metric/imperial to the imperial/metric system, e.g. pounds to euros, kilometres to miles or pounds to kilos. http://calculator-converter.com/converter_miles_to_kilometers_mi_to_km_calculator.php - Integrate a cool and advanced script into your own webpage, e.g. calculator