Archive for ‘Programming’

August 9th, 2010

Simple PHP get URI or Segment element

This script takes any uri or segment from the url of the current page and assigns it to a $uri variable. It is very easy to implement so enjoy.

php 

$uri = $_SERVER['REQUEST_URI'];
$pieces = explode("/", $uri);
$uri_3 = $pieces[3];

/php

Refferenses:

URI -Term used to collectively refer to URLs, URNs, and URCs.
lcweb2.loc.gov/ammem/techdocs/repository/gengloss.html

$_SERVER is an array containing information such as headers, paths, and script locations. http://php.net/manual/en/reserved.variables.server.php

explode() Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter. http://php.net/manual/en/function.explode.php

Tags:
December 21st, 2009

C Floating Point Division Example

/* preprocessor directive */
#include <stdio.h>
/* main() function: beginning */
int main()
{
float x,y,z;
x = 4.0;
y = 5.0;
z = x/y;
printf(”%f\n”, z);
return 0;
}
/* end of main() function */


SOURCE CODE