1 lip 2010

Zamiana pierwszych liter w wyrazach na duże

$w_city = 'mapa biala podlaska';
$w_city_t = explode(' ',$w_city);
$w_city_t = array_map('ucfirst' ,$w_city_t);
$w_city = implode(' ', $w_city_t);
echo $w_city;

Mapa Biala Podlaska

$w_city = 'mapa bielsko-biala';
$w_city_t = preg_split('/[ -]+/',$w_city);
$w_city_t = array_map('ucfirst' ,$w_city_t);
$w_city = implode(' ', $w_city_t);
echo $w_city;

Mapa Bielsko Biala

$w_city = 'mapa bielsko-biala';
$w_city = ucwords($w_city);
$w_city = implode('-', array_map('ucfirst' , explode('-',$w_city)));
echo $w_city;

Mapa Bielsko-Biala

30 cze 2010

Przeformatowanie daty za pomoca funkcji str_pad

php:

$tstartdate = '2010-7-1';
$a_tstartdate = explode('-', $tstartdate);
$data_sd['d'] = str_pad($a_tstartdate[2], 2, '0', STR_PAD_LEFT);
$data_sd['m'] = str_pad($a_tstartdate[1], 2, '0', STR_PAD_LEFT);
$data_sd['y'] = $a_tstartdate[0];

smarty:

$smarty->assign('sd_data', $data_sd);

template:
Data wyjazdu:

<input type="text" value="!{$sd_data.d}!" disabled="disabled" size="2" />
<input type="text" value="!{$sd_data.m}!" disabled="disabled" size="2" />
<input type="text" value="!{$sd_data.y}!" disabled="disabled" size="4" />

wynik:
Data wyjazdu: 01 07 2010

26 lis 2009

Wykorzystanie array_unique

$str = '2009.1|2009.2|2009.6|2009.6|2009.6|2009.7 |2009.8|2009.8|2009.9|2009.9|2009.9|2009.10|2009.10|2009.10|2009.10';
echo $str . '<br><br>';

$tab = explode('|', $str);
$tab2 = array_unique($tab);

echo '<pre>'; print_r($tab2); echo '</pre>';
$cnt = count($tab2);

for($i=0; $i<$cnt; $i++) {
 echo $tab2[$i].' ';
}

echo '<br><br>';</p>

foreach($tab2 as $row) {
 echo $row.' ';
}

Wyniki:
2009.1|2009.2|2009.6|2009.6|2009.6|2009.7 |2009.8|2009.8|2009.9|2009.9|2009.9|2009.10|2009.10|2009.10|2009.10
Array
(
    [0] => 2009.1
    [1] => 2009.2
    [2] => 2009.6
    [5] => 2009.7
    [6] => 2009.8
    [8] => 2009.9
    [11] => 2009.10
)

for:
2009.1 2009.2 2009.6 2009.7 2009.8

foreach:
2009.1 2009.2 2009.6 2009.7 2009.8 2009.9 2009.10

18 cze 2009

Porównanie zawartości plików

$file_1 = 'mapy_01.txt';
$file_2 = 'chelm_02.txt';

$table_1 = file($file_1);
$table_2 = file($file_2);

for ($i = 0, $cnt = count($table_1); $i < $cnt; $i++) {
  $tab = explode("\t", chop($table_1[$i]));

  $key = $tab[0].' '.$tab[1].' '.$tab[2];
  $table_test[$key] = $key;
}

for ($i = 0, $cnt = count($table_2); $i < $cnt; $i++) {
  $table_2[$i] = chop($table_2[$i]);
  $tab = explode("\t", $table_2[$i]);

  $key = $tab[3].' '.$tab[4].' '.$tab[5];
  if (!isset($table_test[$key])) {
    $table_niema[] = $table_2[$i];
  }
}
echo "Plik drugi";
echo '<pre>'; print_r($table_2); echo '</pre>';

echo "Brak w pliku pierwszym";
echo '<pre>'; print_r($table_niema); echo '</pre>';