get

by marshall bannana on July 24th, 2010

in comments

Syntax: PHP
Show lines - Hide lines - Show in textbox - Download
// VALIDATION . ini
<?php 
function str_ievpi($arg)
{
	if(
	is_string($arg) &&
	strlen($arg) <= 10 &&
	preg_match('/^(([1-9][0-9]+)|(0-9))$/', $arg) )
	{
		return true;
	}
	else {
		return false;
	}
}
function str_ievpifr($arg, $min, $max)
{
	if(
		str_ievpi($arg) &&
		($arg >= $min) &&
		($arg <= $max)
	)
	return true;
	else 
	return false;
}
?>
 
//STRING 2H ARRAY FUN
<?php
	/*reutrn associative array 
	 * rows, cols
	 * item : 2 dimention array $t['item'][(int)(_LINE number_)][(int)(_cell_)] 
	 * 
	 * args : $s array do check, $separator*/
 
	function string_2h_array($s, $separator = '|'){
		$lines = explode("\n", trim($s));
		$lines_count = count($lines);
		$t = array();
 
	  for($i=0; $i<$lines_count; $i++){
			$t[] = explode($separator, trim($lines[$i]));
			if(count($t[$i]) != count($t[0])){
				return false;
			}
		}
 
		return array(
			'rows' => count($lines),
			'cols' => count($t[0]),
			'item' => $t
		);
	}
 
	/*reutrn associative array 
	 * rows, cols
	 * item : 2 dimention array $t['item'][(int)(_COLUMN number_)][(int)(_cell_)] 
	 * 
	 * args : $s array do check, $separator*/
 
	function string_2v_array($s, $separator='|'){
		$lines = explode("\n", $s);
		$lines_counter = count($lines); 
		$line_length = count(explode($separator, trim($lines[0]))); 
 
		for($i =0; $i<$lines_counter; $i++){
			$line = explode($separator, trim($lines[$i]));
			if(count($line) != $line_length)
				return false;
 
			for($j = 0; $j<$line_length; $j++){
				$t[$j][] = $line[$j];
			}
		}
		return array(
			'rows' => $lines_counter,
			'cols' => $line_length,
			'item' => $t
		);
	}
 
	/* check array for errors. If something is wrong function returns array with bad lines 
	 * else returns TRUE
	 * 
	 * args : $s array do check, $separator*/
	function string_array_is_ok($s, $separator = '|'){
		$lines = explode ("\n", trim($s));
		$ok = count(explode($separator, trim($lines[0])));
		$errs = array();
 
		foreach($lines as $line){
			if(count(explode($separator, trim($line))) != $ok){
				$errs = trim($line);
 
			}
			if(empty($errs))
				return true;
			else
				return $errs;
 
		}
	}
 
	/* devide 1 dimention array to 2 dimention array $t['item'][(int)(_LINE number_)][(int)(_cell_)]
	 * 
	 * args $a - array to devide
	 * 		$col - how many columns
	 * 		$default separator*/
	function array_1dim_to_2dimH($a, $col, $default = '')
	{
		$items = count($a);
		$rows = round(ceil($items/$col));
		$result = array();
 
		for($i=0; $i < $rows; $i++)
		{
			for($j = 0; $j< $col; $j++)
			{
				$index = $i * $col + $j;
				if(isset($a[$index]))
				{
					$result[$i][$j] = $a[$index];
				} else {
					$result[$i][$j] = $default;
				}
			}
		}
		return array(
			'rows' => $rows,
			'cols' => $col,
			'items' => $result
		);
	}
 
	/* devide 1 dimention array to 2 dimention array $t['item'][(int)(_COLUMN number_)][(int)(_cell_)]
	 * 
	 * args $a - array to devide
	 * 		$col - how many columns
	 * 		$default separator*/
	function array_1dim_to_2dimV($a, $col, $default = '')
	{
		$items = count($a);
		$rows = round(ceil($items/$col));
		$result = array();
 
		for($i=0; $i < $col; $i++)
		{
			for($j = 0; $j < $rows; $j++)
			{
				$index = $i * $rows + $j;
				if(isset($a[$index]))
				{
					$result[$i][$j] = $a[$index];
				} else {
					$result[$i][$j] = $default;
				}
			}
		}
		return array(
			'rows' => $rows,
			'cols' => $col,
			'items' => $result
		);
	}
 
?>
 
<?php 
	$path = 'projekty/20-03/';
	require_once 'validation.inc.php';
	require_once 'vh-array.inc.php';
	$types_and_folders = string_2h_array(file_get_contents($path.'spis.txt'), "*");
 
//ACTUAL
//PROBLEM
//CANNOT
//PASST THE THE FUNCTON str_ievpifr $types_and_folders['rows'] =7!
 
	if(isset($_GET['nr']) && str_ievpifr($_GET['nr'],0,$types_and_folders['rows'])) //nie moze przejsc testu? O_O
	{
		$number = $_GET['nr'];
	} else {
		$number = 0;
	}
 
?>
 
<?php 
	for($i=0; $i<$types_and_folders['rows']; $i++)
	{
		echo '<li><a href="20-3.php?nr='.($i).'">'.$types_and_folders['item'][$i][0].'</a></li>';
	}
?>
 
<?php 
	$files_and_descriptions = string_2h_array(
		file_get_contents($path.$types_and_folders['item'][$number][1].'/'.$types_and_folders['item'][$number][1].'.txt')
	);
 
	for($i=0; $i<$files_and_descriptions['rows']; $i++)
	{
		echo '<img src="'.$path.$types_and_folders['item'][$number][1].'/'.$files_and_descriptions['item'][$i][0].
		'"alt ="'.$files_and_descriptions['item'][$i][1].'"></br>';
	}
?>
 

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS