Encoding

Here is a generated php link:

What If for example the value of “name”, instead of “Kevin”, contains sensible characters like “&” or spaces that interfere with an URL?

We are going to use URL encoding

We are going to do some transformations using php to make sure the value is safe before it is sent to the URL

Lets start by setting up some variables:

How can we put together a URL that’s going to be encoded and not break for us?

We are going to use the following functions:

  • rawurlencode() – we will use this before the question mark;
  • urlencode() – we will use this after the question mark;
  • htmlspecialchars() – escapes any html that might due bad things to our html page.

Our URL will be like this:

We’ve done two things, cleaned up the link so that we can use it and then we’ve done our htmlspecialchars so that we can safely display that link.

URL Values

To pass values we add “?” to a page like this:

$_GET is an associative array of variables passed to the current script via the URL parameters.

We can pass these variables into an associative array which we can access using $_GET.

 

Array Functions

We begin by defining an array:

Now lets analyze the following array functions

1. Count Function

Counts all elements in an array

2. Max Function

Finds the highest value in an array

3. Min Function

Finds the lowest value in an array

4. Sort and Rsort Function

Sort – sorts an array; Rsort – sorst the array in reverse order.

5. Implode Function

This function joins array elements with a string

This is very helpful for array’s that contain names. We can display them and separate each name by comma.

6. Explode Function

Returns an array of strings splitting it on boundaries formed by the string delimiter.

To see the results we can print it

7. in_array Function

Checks if a value exists in an array, returns true of false.

Arrays

This returns position 1, meaning value “8″ while the second echo returns position 0, meaning the value “4″.

Important: arrays are numbered starting with 0.

This returns “dog”.

What if we do this?

This will return “Array”. We can put this inside another variable or we can echo a value from it like this:

This will return “y”

What happens if we want to put things into the pockets of the array?

This will replace “dog” with “cat”.

We can lable the array

This will echo “Kevin”.

This will replace Kevin with Josh

This will print the array’s content. Great for debugging

For a better wiew of the content of the array we can use the “pre” tag, which is a HTML command that says “don’t apply any formatting”.