In part 5 of my Web Design and Programming tutorial I will cover the following topics:
How to turn a string into an array
How to turn an array into a string
How to sort an array
How to pull data from a file and store it in an array
And, I’ll also go over a bunch of other functions specific to arrays. If you missed part 1 of this tutorial it is available here Web Design and Programming.
All of the code in this tutorial will follow the video. Use it in any way that you would like.
If you have any questions or comments leave them below and I’ll answer them.
<?php
# An array is just a big box containing many similar boxes
# This information is similar to each other
# All the the information or values have a coresponding key or label associated with it
# An array can contain any combination of numbers, strings or other arrays
# Create basic array with key value pairs
/* $myInfo = array(“Name” => “Derek”, “Street” => “123 Main St”, “City” => “Pittsburgh”);
# Get the value by calling for the key associated with it
echo “My name is “, $myInfo[“Name”], “<br /><br />”;
$moreInfo = array(“State” => “PA”, “Age” => 35);
# Merge 2 arrays into one
$myInfo = array_merge($myInfo, $moreInfo);
# Iterate through the array with the foreach looping device
foreach( $myInfo as $key => $value)
{
echo $key, ” “, $value, “<br />”;
}
echo “<br /><br />”;
# Search for a key in an array
if(array_key_exists(“Name”, $myInfo)) echo “The name stored is “, $myInfo[“Name”];
echo “<br /><br />”;
# Search for a value in an array
$citySearch = array_search(“Pittsburgh”, $myInfo);
echo “The key for the city is “, $citySearch;
echo “<br /><br />”;
print_r (array_keys($myInfo)); # Short cut to provide the arrays keys
echo “<br /><br />”;
print_r (array_values($myInfo)); # Short cut to provide the arrays keys & values
echo “<br /><br />”;
In this web design and programming video tutorial I’ll show you how to use looping statements with PHP. If you missed the first part of this tutorial it is here Web Design and Programming.
Here I continue covering Web Design and Programming using all of the most used languages being HTML, CSS, JavaScript, PHP, MySQL, etc. If you missed my first video, you should watch that first Web Design and Programming part 1.
In this specific tutorial I’ll cover the following:
I have received tons of requests for tutorials. So, I’ve decided to create a massive tutorial that answers them all. In this tutorial I’ll focus on Web Design and Programming using all of the tools required. You should check out my Learn HTML Tutorial if you haven’t ahead of time.
I’ll continue this tutorial, with your input, until you can do pretty much anything in Web Design and Programming. Leave questions and comments below, because you are going to totally control everything I cover here.
I’ll start off with the basics of PHP and move on from there with tons of examples. Of course, all of the code used will follow the video.
// You can use short tags but it is not recommended doesn’t work in 6
# You can also comment code like this
/* Here is a
multiline comment
*/
echo “<p>Random Text</p>”;
print(“<p>You can print with braces</p>”);
print “<p>or without
them!</p>”;
$randVar = “Cats”;
echo “<p>”, $randVar, ” are funny</p>”;
printf(“<p>My name is %s I’m %d years old and
pi is equal to %.2f</p>”, ‘Derek’, 35, 3.14);
// Variables must start with a $ then letter or _ and then numbers
// Variables are case sensitive & don’t require definition before use
$boolEx1 = false; // 0 or false equals false
$boolEx2 = 1; // true equals any number but 0
Well it has been a long trip, but I’m going to wrap up the Python Tutorial here. Before I stopped I wanted to answer one question posed to me which was to create a program that automated the process of getting demographics.
I didn’t have much time to perfect this and I plan to come back, but this program will grab tons of demographics for you including:
In this Python Tutorial I show you how to build a simple chat server. All you need to do this are the pre-installed modules: asyncore, asynchat and socket.
The code then basically does the following:
Assigns a special address for each person that goes to the port (Socket)
Listens for any messages
When it gets a new message it sends it through the socket and into the port
A dispatcher decides what code should be called based off of the message sent
In this video tutorial I show you how to create dynamic websites with Python. This is the quickest and easiest way to start using Python in much the same way as PHP is used.
I previously taught you how to scrap websites for information in this tutorial Python Website Scraping. Here I’ll show you how to scrap and then display that information dynamically on the internet.
Leave any questions or comments below and here are all of my previous Python Video Tutorial’s:
Here I continue to teach you how to use the Tkinter GUI module built into Python. I build an application that allows you to input files, edit them and then save them. I specifically show you how to make the following GUI widgets with Tkinter:
Menu Bars
Multi-Line Editable Text Boxes
Drop Down Menus
If you haven’t seen the previous Tkinter tutorial you should definitely check it out below first. Otherwise this won’t make any sense.
In the previous tutorial I showed you how to grab the following from any sites rss feed using Python:
Title of Articles
All the Content from the Original Article
Link to the Original Article
This is known as website scraping and it is the major component used by all automated website applications. One thing I didn’t cover is how to strip the html tags from those articles, so I’ll do that in this video.
I was asked today to provide a big personality test that provided easy to understand results. Below I provide a personality quiz and answer sheet along with a detailed report on all 16 possible personality types.
This personality quiz is based off of Myers Briggs, with some additions from more recently developed personality analysis. I hope you find it useful, because I’ve been working on this for some time.
In this video tutorial I show you how to scrap websites. I introduce 2 new modules being UrlLib and Beautiful Soup. UrlLib is preinstalled on Python, but you have to install Beautiful Soup for it to work.
Beautiful Soup is available at their website. If you are using Python versions previous to Python 3.0 get this version Beautiful Soup for Python previous to 3.0. If you are using Python 3.0 or higher get this version of Beautiful Soup.
In this Python Video Tutorial, I will show you how to create databases using the Python SQLite module. SQLite is great because it:
Provides most of the basic database structure you want
Doesn’t require you to have an actual database server running
Provides SQL querying capabilities
Is included with Python by default
You enter and retrieve information from an SQLite database just like you do with any other database, by using SQL. Here is a tutorial on how to program with SQL if you don’t know how SQL Statements Video Tutorial. In that tutorial I focus on MySQL, but everything a say about SQL is nearly identical.
In this video tutorial on how to use Python, I will focus on how to use an interesting Python Module called Shelve. Shelve allows you to store data in files similar to how a database works. It is very easy to use and provides a convenient way to take advantage of the power of Python dictionaries while providing you with the ability to change the data.
I’ll continue in the next tutorial to cover another interesting Python Module called SQLite. It is a Module that can be used as if it was a database meaning:
I realized today that I haven’t mentioned my diet in many months. The reason why most people stop talking about their diet is because it has failed. Mine hasn’t!!!
For those who are unaware, last year at about this time I weighed 248lbs and I decided I wanted to lose weight. I created a diet plan that was based around these core principles:
Eat the number of calories I needed to lose 70 lbs (Around 1400 calories)
Eat food that was high in fiber and makes your body feel full
Avoid foods high in calories, fat, cholesterol and sodium
In this tutorial, I continue to explain how Object Oriented Programming is used with Python 2.7. I cover some of the more complicated subjects including how to:
Allow the user to define an infinite number of attributes
Use Inheritance and what it is
Override Methods
Use Polymorphism and what it is
Inherit from 2 more more classes
Use many of the built in object methods in Python
If you don’t completely understand Object Oriented Programming after this and the first part of this tutorial Python Object Oriented Programming. Please leave a comment below and I’ll do whatever I can to explain this important subject.
Like always, a lot of code follows the video. If you have any questions or comments leave them below. And, if you missed my other Python Tutorials they are available here:
Note: You have to insert the white space and everything will work. I could have styled it with HTML, but that would have required you to erase all of the tags. Hope this helps?
#! /usr/bin/python
__metaclass__ = type
class Animal:
__name = “No Name”
__owner = “No Owner”
def __init__(self, **kvargs): # The constructor function called when object is created
self._attributes = kvargs
# There is a function called a destructor __del__, but its best to avoid it
def __hiddenMethod(self): # A hidden method
print “Hard to Find”
return
class Dog(Animal):
def __init__(self, **kvargs): # Not needed unless you plan to override the super
super(Dog, self).__init__() # This wouldn’t work without the second line
self._attributes = kvargs
def noise(self): # Overriding the Animal noise function
print(‘Woof, woof’)
Animal.noise(self)
return
class Cat(Animal):
def __init__(self, **kvargs): # Not needed unless you plan to override the super
super(Cat, self).__init__()
self._attributes = kvargs
def noise(self):
print(‘Meow’)
return
def noise2(self):
print(‘Purrrrr’)
return
class Dat(Cat,Dog):
def __init__(self, **kvargs): # Not needed unless you plan to override the super
super(Dat, self).__init__()
self._attributes = kvargs
def move(self):
print(‘Chases Tail’)
return
def playWithAnimal(Animal): # This is polymorphism
Animal.noise()
Animal.eat() # Works even if the method isn’t in Cat because Cat is an Animal
Animal.move()
print(Animal.get_attributes(‘__name’))
print(Animal.get_attributes(‘__owner’))
print ‘\n’
Animal.set_attributes(‘clean’,”Yes”)
print(Animal.get_attributes(‘clean’))
print issubclass(Cat, Animal) # Checks if Cat is a subclass of Animal
print Cat.__bases__ # Prints out the base class of a class
print sophie.__class__ # Prints the objects class
print sophie.__dict__ # Prints all of an objects attributes