18 Maj 2014

Sprawdzenie czy w pliku zanajdują się wybrane imiona

format pliku (ludzie.txt):
karolina
pawel
kajetan

funkcja:

function get_data_from_file($param = null) {
  $file = $param['file'];
  $data_file = file_get_contents($file);
  $data_tmp = preg_split("//", $data_file);
  return $data_tmp;
}

uruchomienie:

$ludzie=get_data_from_file(array('file'=>'ludzie.txt'));
if(in_array("pawel", $ludzie)) {
$is_in_ludzie=true;
}
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

4 Sie 2009

Sprawdzanie osiągalności adresów url

function curlRequest($url) {
  $ch=curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  curl_setopt($ch, CURLOPT_HEADER, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_NOBODY, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

  $httpHeader = array(
    "Content-Type: text/xml; charset=UTF-8",
    "Content-Encoding: UTF-8"
  );

  curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);

  $data=curl_exec($ch);
  $info=curl_getinfo($ch);
  $errno=curl_getinfo( $ch, CURLINFO_HTTP_CODE );
  $finalurl=curl_getinfo( $ch, CURLINFO_EFFECTIVE_URL );

  curl_close($ch);

  if(preg_replace("/\/$/", "", $finalurl)==preg_replace("/\/$/", "", $url))
    $finalurl = ";
    return $errno.'|'.$finalurl;
}

$urls = 'www.wolakorybutowa.pl';
$tab_urls = preg_split('//', $urls, -1, PREG_SPLIT_OFFSET_CAPTURE);

for($i=0; $i $data = curlRequest('http://'.trim(chop($tab_urls[$i][0])));
  $tab_urls[$i][1] = $data;
}
print_r($tab_urls);