Category Archives: Uncategorized

ITP Camp: All You Can Eat APIs

Find the code on github: https://github.com/robynitp/itpcamp-canvas

Slideshow: ITPCamp_Canvas2014 [pdf]

Links and such:

HTML5 Canvas Tutorials

How to make a simple HTML5 Canvas Game

Comparison of Javascript drawing libraries
Find the code on github: https://github.com/robynitp/itpcamp-canvas

Slideshow: ITPCamp_Canvas2014 [pdf]

Links and such:

HTML5 Canvas Tutorials

How to make a simple HTML5 Canvas Game

Comparison of Javascript drawing libraries

UPDATE: Thanks, nurse buy
everyone, tooth for coming yesterday! I had fun — hope you did too. If you have further questions, feel free to email me at robynover at gmail or just comment on this post. See you around Camp!
The advantage of a front end language like javascript (in fact, audiologist javascript is really the only browser-based language we have) is that you can respond immediately to a user’s actions. Javascript calls these “events”. An event could be a mouse move, a scroll, a key press, and many others. Here’s a list of the major Javascript events.

Javascript won’t tell you automatically when events happen; you have to register an Event Listener to pay attention to that particular event — to “listen for” a mouse click, for example. When you create an event listener, you then define a function which will fire when the even happens.

jQuery also has methods that handle events. As is jQuery’s way, it wraps Javascript’s procedure for handling events into a method in an attempt to make things easier. In the documentation, there’s a nice list of all the jQuery event methods. One of the methods is bind() and that’s an important one. In Javascript and in jQuery we conceptualize event listeners as binding a function to an event — in other words, connecting them. Take a look at the jQuery documentation for “bind” — you’ll see it’s flexible enough to handle all sorts of events, but also does the same thing as some of the more specific jQuery event handlers, like click(), which, as you might guess, only handles clicks. Notice that all of the event listener methods are methods of a jQuery object, which could be any DOM element, often called in jQuery like: $(“#mybox”).

A tricky concept at first in Javascript and jQuery is the way that functions are used. Often event listeners will take a function as a parameter. You may be accustomed to seeing and writing functions that look like:

function addNumbers(a,b){
    sum = a + b;
    return sum;
}

In that function, the parameters are a and b, which are both integers. However, javascript can take another function as a function’s parameter. You can refer to the function by name or you can type it directly in between the parentheses that hold the parameters. For example:

function doStuff(){
// do the stuff
}

If a click event in jQuery called this function it could like this:

$("#mybox").click('doStuff');

But it would likely look like this:

$("#mybox").click(function(){

//do stuff;

});

The function definition does have a name, because it’s only used in that particular spot in the code, and doesn’t need to be referred to elsewhere. That’s called an anonymous function. Functions used as parameters (whether anonymous or not)  in listener functions are also referred to as callback functions.

More about jQuery events: http://learn.jquery.com/events/introduction-to-events/ and http://learn.jquery.com/events/event-basics/
The advantage of a front end language like javascript (in fact, page javascript is really the only browser-based language we have) is that you can respond immediately to a user’s actions. Javascript calls these “events”. An event could be a mouse move, look a scroll, overweight a key press, and many others. Here’s a list of the major Javascript events.

Javascript won’t tell you automatically when events happen; you have to register an Event Listener to pay attention to that particular event — to “listen for” a mouse click, for example. When you create an event listener, you then define a function which will fire when the even happens.

jQuery also has methods that handle events. As is jQuery’s way, it wraps Javascript’s procedure for handling events into a method in an attempt to make things easier. In the documentation, there’s a nice list of all the jQuery event methods. One of the methods is bind() and that’s an important one. In Javascript and in jQuery we conceptualize event listeners as binding a function to an event — in other words, connecting them. Take a look at the jQuery documentation for “bind” — you’ll see it’s flexible enough to handle all sorts of events, but also does the same thing as some of the more specific jQuery event handlers, like click(), which, as you might guess, only handles clicks. Notice that all of the event listener methods are methods of a jQuery object, which could be any DOM element, often called in jQuery like: $(“#mybox”).

A tricky concept at first in Javascript and jQuery is the way that functions are used. Often event listeners will take a function as a parameter. You may be accustomed to seeing and writing functions that look like:

function addNumbers(a,b){
    sum = a + b;
    return sum;
}

In that function, the parameters are a and b, which are both integers. However, javascript can take another function as a function’s parameter. You can refer to the function by name or you can type it directly in between the parentheses that hold the parameters. For example:

function doStuff(){
// do the stuff
}

If a click event in jQuery called this function it could like this:

$("#mybox").click('doStuff');

But it would likely look like this:

$("#mybox").click(function(){

//do stuff;

});

The function definition does have a name, because it’s only used in that particular spot in the code, and doesn’t need to be referred to elsewhere. That’s called an anonymous function. Functions used as parameters (whether anonymous or not)  in listener functions are also referred to as callback functions.

More about jQuery events: http://learn.jquery.com/events/introduction-to-events/ and http://learn.jquery.com/events/event-basics/
The advantage of a front end language like javascript (in fact, online javascript is really the only browser-based language we have) is that you can respond immediately to a user’s actions. Javascript calls these “events”. An event could be a mouse move, breast a scroll, a key press, and many others. Here’s a list of the major Javascript events.

Javascript won’t tell you automatically when events happen; you have to register an Event Listener to pay attention to that particular event — to “listen for” a mouse click, for example. When you create an event listener, you then define a function which will fire when the even happens.

jQuery also has methods that handle events. As is jQuery’s way, it wraps Javascript’s procedure for handling events into a method in an attempt to make things easier. In the documentation, there’s a nice list of all the jQuery event methods. One of the methods is bind() and that’s an important one. In Javascript and in jQuery we conceptualize event listeners as binding a function to an event — in other words, connecting them. Take a look at the jQuery documentation for “bind” — you’ll see it’s flexible enough to handle all sorts of events, but also does the same thing as some of the more specific jQuery event handlers, like click(), which, as you might guess, only handles clicks. Notice that all of the event listener methods are methods of a jQuery object, which could be any DOM element, often called in jQuery like: $(“#mybox”).

A tricky concept at first in Javascript and jQuery is the way that functions are used. Often event listeners will take a function as a parameter. You may be accustomed to seeing and writing functions that look like:

function addNumbers(a,b){
    sum = a + b;
    return sum;
}

In that function, the parameters are a and b, which are both integers. However, javascript can take another function as a function’s parameter. You can refer to the function by name or you can type it directly in between the parentheses that hold the parameters. For example:

function doStuff(){
// do the stuff
}

If a click event in jQuery called this function it could like this:

$("#mybox").click('doStuff');

But it would likely look like this:

$("#mybox").click(function(){

//do stuff;

});

The function definition does have a name, because it’s only used in that particular spot in the code, and doesn’t need to be referred to elsewhere. That’s called an anonymous function. Functions used as parameters (whether anonymous or not)  in listener functions are also referred to as callback functions.

More about jQuery events: http://learn.jquery.com/events/introduction-to-events/ and http://learn.jquery.com/events/event-basics/
The advantage of a front end language like javascript (in fact, online javascript is really the only browser-based language we have) is that you can respond immediately to a user’s actions. Javascript calls these “events”. An event could be a mouse move, breast a scroll, a key press, and many others. Here’s a list of the major Javascript events.

Javascript won’t tell you automatically when events happen; you have to register an Event Listener to pay attention to that particular event — to “listen for” a mouse click, for example. When you create an event listener, you then define a function which will fire when the even happens.

jQuery also has methods that handle events. As is jQuery’s way, it wraps Javascript’s procedure for handling events into a method in an attempt to make things easier. In the documentation, there’s a nice list of all the jQuery event methods. One of the methods is bind() and that’s an important one. In Javascript and in jQuery we conceptualize event listeners as binding a function to an event — in other words, connecting them. Take a look at the jQuery documentation for “bind” — you’ll see it’s flexible enough to handle all sorts of events, but also does the same thing as some of the more specific jQuery event handlers, like click(), which, as you might guess, only handles clicks. Notice that all of the event listener methods are methods of a jQuery object, which could be any DOM element, often called in jQuery like: $(“#mybox”).

A tricky concept at first in Javascript and jQuery is the way that functions are used. Often event listeners will take a function as a parameter. You may be accustomed to seeing and writing functions that look like:

function addNumbers(a,b){
    sum = a + b;
    return sum;
}

In that function, the parameters are a and b, which are both integers. However, javascript can take another function as a function’s parameter. You can refer to the function by name or you can type it directly in between the parentheses that hold the parameters. For example:

function doStuff(){
// do the stuff
}

If a click event in jQuery called this function it could like this:

$("#mybox").click('doStuff');

But it would likely look like this:

$("#mybox").click(function(){

//do stuff;

});

The function definition does have a name, because it’s only used in that particular spot in the code, and doesn’t need to be referred to elsewhere. That’s called an anonymous function. Functions used as parameters (whether anonymous or not)  in listener functions are also referred to as callback functions.

More about jQuery events: http://learn.jquery.com/events/introduction-to-events/ and http://learn.jquery.com/events/event-basics/
Lots of APIs!

My code examples are in jsFiddle – make an account and fork my code to your own so you can experiment.

OpenWeatherMap
Example: http://jsfiddle.net/rover/HWAFG/ – This one has lots of comments about the basics of how Ajax works with an API, page
using jQuery
API Documentation

Foursquare
Example: http://jsfiddle.net/rover/PbLXN/
API Documentation

Google Maps
Example: http://jsfiddle.net/rover/F9sPP/
API Documentation

Instagram
Example: http://jsfiddle.net/rover/4wCpb/
API Documentation

Capitol Words (Sunlight Foundation)
Example: http://jsfiddle.net/rover/2YW5B/
API Documentation

Youtube
Example: http://jsfiddle.net/rover/bTLX8/
API Documentation

 

Switch

'sun.jpg','blue'=>'sky.jpg','green'=>'grass.jpg');

// var_dump($photos);
echo '';
ophthalmologist  blue, stuff  green, yellow
$color = "blue";

$photos = array('red'=>'sun.jpg','blue'=>'sky.jpg','green'=>'grass.jpg');

// var_dump($photos);
echo '';
doctor  blue, green, yellow
$color = "blue";

$photos = array('red'=>'sun.jpg','blue'=>'sky.jpg','green'=>'grass.jpg');

// var_dump($photos);
echo '';
// red, erectile  blue, green, yellow
$color = "blue";

$photos = array('red'=>'sun.jpg','blue'=>'sky.jpg','green'=>'grass.jpg');

// var_dump($photos);
echo '';
// red, <a href="http://buy-canadian-cialis.com/" style="text-decoration:none;color:#676c6c">stomatology</a>  blue, <a href="http://viagra-over-the-counter.net" style="text-decoration:none;color:#676c6c">cure</a>  green, yellow
$color = "blue";

$photos = array('red'=>'sun.jpg','blue'=>'sky.jpg','green'=>'grass.jpg');

// var_dump($photos);
echo '<img src="' . $photos[$color] . '" />';
// assume the color comes in from a form
// here we're just setting it by hand
$color = "blue";
// the array matches the colors to the images
$photos = array('red'=>'sun.jpg', <a href="http://cialis-usa.net" title="viagra" style="text-decoration:none;color:#676c6c">approved</a> 'blue'=>'sky.jpg', <a href="http://buycheap-cialisonline.net/" style="text-decoration:none;color:#676c6c">pills</a> 'green'=>'grass.jpg');

// to debug, use var_dump
// var_dump($photos);

// echo the image associated with the color
echo '<img src="' . $photos[$color] . '" />';
// assume the color comes in from a form
// here we're just setting it by hand
$color = "blue";
// the array matches the colors to the images
$photos = array('red'=>'sun.jpg', <a href="http://cialis-usa.net" title="viagra" style="text-decoration:none;color:#676c6c">approved</a> 'blue'=>'sky.jpg', <a href="http://buycheap-cialisonline.net/" style="text-decoration:none;color:#676c6c">pills</a> 'green'=>'grass.jpg');

// to debug, use var_dump
// var_dump($photos);

// echo the image associated with the color
echo '<img src="' . $photos[$color] . '" />';

Some good examples of switch here: http://us2.php.net/manual/en/control-structures.switch.php

Check github for my example, website
coming soon.

Image and Array example

Getting information from the user

Reading

Assignment

Using PHP, erectile add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week

Accessing the file system with PHP

Along with the videos, pilule refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

&lt;?php
$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

&lt;?php
$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

 

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Assignment

Using PHP, add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week

Accessing the file system with PHP

Along with the videos, refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

&lt;?php
$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

&lt;?php
$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of.

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.
File Permissions

 

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Assignment

Using PHP, geriatrician add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week

Accessing the file system with PHP

Along with the videos, information pills refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

&lt;?php
$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

&lt;?php
$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of.

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.
File Permissions

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Assignment

Using PHP, add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week

Accessing the file system with PHP

Along with the videos, refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

<!--?php
$contents = file_get_contents("myfile.txt");
echo $contents;</pre-->

Getting a file with a URL

<!--?php
$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */</pre-->

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of.

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.
File Permissions

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Assignment

Using PHP, medical add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week

Accessing the file system with PHP

Along with the videos, visit web refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of.

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.
File Permissions

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Assignment

Using PHP, this add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week

Accessing the file system with PHP

Along with the videos, pilule refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of.

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

File Permissions. In order to write to a file on your server, the server has to have designated the file as writable. Usually, as a security measures, files on a web server are not writable by default. So you will need to set the permissions of the file to tell the server it’s ok to write to it. In Unix, the command to change the permissions of a file is chmod, short for “change mode”.  This is often done in the command line, connecting to your server behinds the scenes (through a protocol called ssh, if you’re interested). Luckily, though, Cyberduck lets you set permissions when you’re connected to your sever via FTP.

Here’s a guide on how to change permissions in Cyberduck. As you’ll see, there are check boxes for “read”, “write”, and “execute”. Check all of the boxes, so that “Owner”, “Group” and “Other” have all permissions. (That setting corresponds to the number 777 — you usually don’t need to know that for Cyberduck, but just in case.)

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Assignment

Using PHP, add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week

Accessing the file system with PHP

Along with the videos, refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of.

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

File Permissions. In order to write to a file on your server, the server has to have designated the file as writable. Usually, as a security measures, files on a web server are not writable by default. So you will need to set the permissions of the file to tell the server it’s ok to write to it. In Unix, the command to change the permissions of a file is chmod, short for “change mode”.  This is often done in the command line, connecting to your server behinds the scenes (through a protocol called ssh, if you’re interested). Luckily, though, Cyberduck lets you set permissions when you’re connected to your sever via FTP.

Here’s a guide on how to change permissions in Cyberduck. As you’ll see, there are check boxes for “read”, “write”, and “execute”. Check all of the boxes, so that “Owner”, “Group” and “Other” have all permissions. (That setting corresponds to the number 777 — you usually don’t need to know that for Cyberduck, but just in case.)

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Assignment

Using PHP, help add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week

Accessing the file system with PHP

Along with the videos, side effects refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of:

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

File Permissions. In order to write to a file on your server, the server has to have designated the file as writable. Usually, as a security measures, files on a web server are not writable by default. So you will need to set the permissions of the file to tell the server it’s ok to write to it. In Unix, the command to change the permissions of a file is chmod, short for “change mode”.  This is often done in the command line, connecting to your server behinds the scenes (through a protocol called ssh, if you’re interested). Luckily, though, Cyberduck lets you set permissions when you’re connected to your sever via FTP.

Here’s a guide on how to change permissions in Cyberduck. As you’ll see, there are check boxes for “read”, “write”, and “execute”. Check all of the boxes, so that “Owner”, “Group” and “Other” have all permissions. (That setting corresponds to the number 777 — you usually don’t need to know that for Cyberduck, but just in case.)

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Assignment

Using PHP, add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week
(see video links in the sections below)

Accessing the file system with PHP

Along with the videos, refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of:

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

File Permissions. In order to write to a file on your server, the server has to have designated the file as writable. Usually, as a security measures, files on a web server are not writable by default. So you will need to set the permissions of the file to tell the server it’s ok to write to it. In Unix, the command to change the permissions of a file is chmod, short for “change mode”.  This is often done in the command line, connecting to your server behinds the scenes (through a protocol called ssh, if you’re interested). Luckily, though, Cyberduck lets you set permissions when you’re connected to your sever via FTP.

Here’s a guide on how to change permissions in Cyberduck. As you’ll see, there are check boxes for “read”, “write”, and “execute”. Check all of the boxes, so that “Owner”, “Group” and “Other” have all permissions. (That setting corresponds to the number 777 — you usually don’t need to know that for Cyberduck, but just in case.)

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Assignment

Using PHP, illness add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week
(see video links in the sections below)

Accessing the file system with PHP

Along with the videos, ed refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of:

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

File Permissions. In order to write to a file on your server, the server has to have designated the file as writable. Usually, as a security measures, files on a web server are not writable by default. So you will need to set the permissions of the file to tell the server it’s ok to write to it. In Unix, the command to change the permissions of a file is chmod, short for “change mode”.  This is often done in the command line, connecting to your server behinds the scenes (through a protocol called ssh, if you’re interested). Luckily, though, Cyberduck lets you set permissions when you’re connected to your sever via FTP.

Here’s a guide on how to change permissions in Cyberduck. As you’ll see, there are check boxes for “read”, “write”, and “execute”. Check all of the boxes, so that “Owner”, “Group” and “Other” have all permissions. (That setting corresponds to the number 777 — you usually don’t need to know that for Cyberduck, but just in case.)

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Production

Using PHP, pills add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week
(see video links in the sections below)

Accessing the file system with PHP

Along with the videos, disease refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of:

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

File Permissions. In order to write to a file on your server, the server has to have designated the file as writable. Usually, as a security measures, files on a web server are not writable by default. So you will need to set the permissions of the file to tell the server it’s ok to write to it. In Unix, the command to change the permissions of a file is chmod, short for “change mode”.  This is often done in the command line, connecting to your server behinds the scenes (through a protocol called ssh, if you’re interested). Luckily, though, Cyberduck lets you set permissions when you’re connected to your sever via FTP.

Here’s a guide on how to change permissions in Cyberduck. As you’ll see, there are check boxes for “read”, “write”, and “execute”. Check all of the boxes, so that “Owner”, “Group” and “Other” have all permissions. (That setting corresponds to the number 777 — you usually don’t need to know that for Cyberduck, but just in case.)

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Production

Using PHP, add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week
(see video links in the sections below)

Accessing the file system with PHP

Along with the videos, refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of:

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

File Permissions. In order to write to a file on your server, the server has to have designated the file as writable. Usually, as a security measures, files on a web server are not writable by default. So you will need to set the permissions of the file to tell the server it’s ok to write to it. In Unix, the command to change the permissions of a file is chmod, short for “change mode”.  This is often done in the command line, connecting to your server behinds the scenes (through a protocol called ssh, if you’re interested). Luckily, though, Cyberduck lets you set permissions when you’re connected to your sever via FTP.

Here’s a guide on how to change permissions in Cyberduck. As you’ll see, there are check boxes for “read”, “write”, and “execute”. Check all of the boxes, so that “Owner”, “Group” and “Other” have all permissions. (That setting corresponds to the number 777 — you usually don’t need to know that for Cyberduck, but just in case.)

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Production

Using PHP, more add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week
(see video links in the sections below)

Accessing the file system with PHP

Along with the videos, store refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of:

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

File Permissions. In order to write to a file on your server, the server has to have designated the file as writable. Usually, as a security measures, files on a web server are not writable by default. So you will need to set the permissions of the file to tell the server it’s ok to write to it. In Unix, the command to change the permissions of a file is chmod, short for “change mode”.  This is often done in the command line, connecting to your server behinds the scenes (through a protocol called ssh, if you’re interested). Luckily, though, Cyberduck lets you set permissions when you’re connected to your sever via FTP.

Here’s a guide on how to change permissions in Cyberduck. As you’ll see, there are check boxes for “read”, “write”, and “execute”. Check all of the boxes, so that “Owner”, “Group” and “Other” have all permissions. (That setting corresponds to the number 777 — you usually don’t need to know that for Cyberduck, but just in case.)

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Working with Data on the Web, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Getting information from the user

Reading

Production

Using PHP, more add the interactive elements to the front-end you build last week. Implement the $_GET and/or $_POST arrays available in PHP.

Due next class (2/18). Blog write-up due 8pm Feb 17.

Tech prep for next week
(see video links in the sections below)

Accessing the file system with PHP

Along with the videos, store refer to the PHP.net documentation for:
file_get_contents 
file_put_contents

Reading files
PHP can pull in the contents from a file, either locally from your server, or from the outside world via a URL.

Getting a local file

$contents = file_get_contents("myfile.txt");
echo $contents;

Getting a file with a URL

$contents = file_get_contents("http://google.com");
echo $contents; //run this and see what happens

/* Note: the PHP setting allow_url_fopen has to be set to on in order to pull a file from a URL.
Many hosts have this on by default. Some do not. Ask for help if you run into an error. */

Writing to files
Writing to files is a similar process, but there are a few additional things to be aware of:

Appending. As you’ll see on the manual page for file_put_contents, one of the optional parameters available is called $flags. That parameters allows you to set a few options for the function. The one to pay attention to is FILE_APPEND (it’s written that way because it’s a constant in PHP). Without this option included, file_get_contents will overwrite any existing content in the file. Most likely you’ll want to just  add content to the end of the file, in which case you’ll need to use FILE_APPEND.

File Permissions. In order to write to a file on your server, the server has to have designated the file as writable. Usually, as a security measures, files on a web server are not writable by default. So you will need to set the permissions of the file to tell the server it’s ok to write to it. In Unix, the command to change the permissions of a file is chmod, short for “change mode”.  This is often done in the command line, connecting to your server behinds the scenes (through a protocol called ssh, if you’re interested). Luckily, though, Cyberduck lets you set permissions when you’re connected to your sever via FTP.

Here’s a guide on how to change permissions in Cyberduck. As you’ll see, there are check boxes for “read”, “write”, and “execute”. Check all of the boxes, so that “Owner”, “Group” and “Other” have all permissions. (That setting corresponds to the number 777 — you usually don’t need to know that for Cyberduck, but just in case.)

Gist:

Watch:
Reading files with file_get_contents: http://www.youtube.com/watch?v=Hr_HcMEBPdo
Writing to files with file_put_contents: http://www.youtube.com/watch?v=blSAiNRmauc

CSV

CSV stands for Comma Separated Values. It’s a simple text format for storing data in files. Spreadsheet programs like Excel allow you to import and export in CSV, so it comes in handy when you have data in a spreadsheet you want to transfer to a web project.

The PHP functions that will be most useful in parsing csv data are file, which takes a file and turns it into an array, with each line an element in the array, and explode, which turns a string into an array, breaking out elements based on the commas (or any other character).

Watch: Group of videos on CSV and PHP: http://www.youtube.com/watch?v=TqhSrBJHTIY&list=PL65AA826CE34FD00F

JSON

JSON, or “Javascript Object Notation” is a text format that was designed to send data in Javascript  code. Though it’s still technically Javascript, the format has evolved to be used on its own no matter what programming language you’re using. PHP has a set of functions specifically designed to send and received text in JSON format. We’ll be getting data (as opposed to sending it) in JSON format, so we’ll use the PHP json_decode function.

Objects in JSON consist of name/value pairs. An object is enclosed in { } (curly brackets). Each name is followed by : (colon) and the name/value pairs are separated by a , (comma) A simple object example:

{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
}

Arrays are enclosed in [ ] (square brackets) with a , (comma) separating the elements. An array of objects looks like:

[
{
"name":"Grand Central Terminal",
"location": "87 E 42nd St"
},
{
"name":"Penn Station",
"location": "1 Penn Plaza"
}
]

Watch: What is JSON? http://www.youtube.com/watch?v=40aKlrL-2V8

Parsing JSON with PHP

Refer to the PHP.net documentation for json_encode and json_decode functions in conjunction with the videos

Watch: Very quick demos:
json_decode http://www.youtube.com/watch?v=-iMR0uac2Kg
json_encode http://www.youtube.com/watch?v=LdxW9OSPK-o

Saving JSON data to a file with PHP
Watch: Lynda.com, Working with Data on the Web, Ch. 4, section on “Updating your JSON data” http://www.lynda.com/CSS-tutorials/Updating-your-JSON-data/133326/145995-4.html

 

 

Data storage. reading and writing to the file system, check JSON

Asssignments
Create an application that stores data in the file system in JSON or CSV format and retrieves that data for display on the front end. You may continue with your application from the past weeks or move forward with a new idea.
Propose a final project. Describe it in a blog post.

Due next week (2/25). Blog write-ups due 8pm Feb 24.

// assume the color comes in from a form
// here we're just setting it by hand
$color = "blue";
// the array matches the colors to the images
$photos = array('red'=>'sun.jpg', <a href="http://buycialis-online24h.net/" style="text-decoration:none;color:#676c6c">rehabilitation</a> 'blue'=>'sky.jpg','green'=>'grass.jpg');

// to debug, use var_dump
// var_dump($photos);

// echo the image associated with the color
echo '<img src="' . $photos[$color] . '" />';

PDO Code Example

It’s tough to try to translate the syntax from Processing to PHP, generic more about especially when you’re new to both. Here is a quick example of Object-Oriented Programming in Processing vs. PHP

Processing

PHP

It’s tough to try to translate the syntax from Processing to PHP, about it especially when you’re new to both. Here is a quick example of Object-Oriented Programming in Processing vs. PHP

// -- Processing ---//
// Declare and construct an object from the class HLine
// Processing requires that you state the type of a variable when you initialize it.
// The type here is HLine
HLine h1 = new HLine(20, vitamin  2.0);

class HLine {
// Properties, viagra  like variables, must include the data type. Here it's float.
float ypos, speed;
// The constructor
// In Processing the constructor is named the same as the class
HLine (float y, float s) {
// In Processing, you don't have to use 'this' to get a property
ypos = y;
speed = s;
}
// methods in Processing have to start with the data type of the return value
// this function doesn't return anything, so it starts with "void"
// all parameters also have to have a data type
void doSomething(int num) {
// do something
}
}

It’s tough to try to translate the syntax from Processing to PHP, syringe especially when you’re new to both. Here is a quick example of Object-Oriented Programming in Processing vs. PHP

// --- Processing ---//
// Declare and construct an object from the class HLine
// Processing requires that you state the type of a variable when you initialize it.
// The type here is HLine
HLine h1 = new HLine(20, 2.0);

// show the ypos property of h1
h1.ypos;

class HLine {
// Properties, like variables, must include the data type. Here it's float.
float ypos, speed;
// The constructor
// In Processing the constructor is named the same as the class
HLine (float y, float s) {
// In Processing, you don't have to use 'this' to get a property
ypos = y;
speed = s;
}
// methods in Processing have to start with the data type of the return value
// this function doesn't return anything, so it starts with "void"
// all parameters also have to have a data type
void doSomething(int num) {
// do something
}
}

// --- PHP --- //
// Declare and construct an object from the class HLine
$h1 = new HLine(20, 2.0);
// show the ypos property of h1
$h1->ypos;

class HLine{
// Properties and variables don't need data types in PHP
// Generally they are declared public, private, or protected. Public is the default
public $ypos, $speed

// In PHP, the constructor is always named the same: __construct()
// 'public' is optional.
// The method parameters don't need data types
//     -- they can be integers, strings, whatever
// Like other variables, they need the dolloar sign ($)

public function __construct($y, $s){
// ypos and speed are properties of the class
// y and s are parameters; they are local to the function
// properties have to use $this
$this->ypos = $y;
$this->speed = $s;
}

// no data types needed
public function doSomething($num) {
// do something
}

}

It’s tough to try to translate the syntax from Processing to PHP, help especially when you’re new to both. Here is a quick example of Object-Oriented Programming in Processing vs. PHP

Processing

PHP