Etiket arşivi: Array

PHP ve SOAP ile TC Kimlik Numarası Doğrulama

<?php
header('Content-type: text/html; charset=utf-8');
$client = new SoapClient("https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?WSDL");
try{
    $result = $client->TCKimlikNoDogrula(array( 'TCKimlikNo' => '11111111111','Ad' => 'MEHMET','Soyad' => 'MUTLU','DogumYili' => '1989'));
    if($result->TCKimlikNoDogrulaResult){
        echo 'TC Kimlik Numarası Geçerli';
    }else{
        echo 'TC Kimlik Numarası Hatalı';
    }
}catch (Exception $ex){
    echo $ex->faultstring;
}
?>

convert_smart_quotes

Microsoft World’e ait özel karakterleri temizlemek için,

function convert_smart_quotes($text){
$text = mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8');

// UTF-8 karakteleri cevir
$text = str_replace(
array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
array("'", "'", '"', '"', '-', '--', '...'),
$text);

// Windows-1252 karakterleri cevir
$text = str_replace(
array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
array("'", "'", '"', '"', '-', '--', '...'),
$text);

// HTML Kod karakterlerini cevir
$text = str_replace(
array("&lsquo;", "&rsquo;", "&ldquo;", "&rdquo;", "&ndash;", "&mdash;", "&hellip;"),
array("'", "'", '"', '"', '-', '--', '...'),
$text);

// Windows-1252 karakterleri cevir
$text = str_replace(
array("&#145;", "&#146;", "&#147;", "&#148;", "&#150;", "&#151;", "&#133;"),
array("'", "'", '"', '"', '-', '--', '...'),
$text);

// Turkce karakterleri cevir
$text = str_replace(
array("&#286;", "&#287;", "&Ouml;", "&ouml;", "&Ccedil;", "&ccedil;", "&#350;", "&#351;", "&#304;", "&#305;", "&Uuml;", "&uuml;"),
array("Ğ", "ğ", 'Ö', 'ö', 'Ç', 'ç', 'Ş', 'ş', 'İ', 'ı', 'Ü', 'ü'),
$text);

return $text;
}

filter_var

<?php
// for filters that accept options, use this format
$options = array(
    'options' => array(
        'default' => 3, // value to return if the filter fails
        // other options here
        'min_range' => 0
    ),
    'flags' => FILTER_FLAG_ALLOW_OCTAL,
);
$var = filter_var('0755', FILTER_VALIDATE_INT, $options);

// for filter that only accept flags, you can pass them directly
$var = filter_var('oops', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

// for filter that only accept flags, you can also pass as an array
$var = filter_var('oops', FILTER_VALIDATE_BOOLEAN,
                  array('flags' => FILTER_NULL_ON_FAILURE));

// callback filter
function foo($value)
{
    $ret = new stdClass;
    $ret->value = filter_var($value, FILTER_VALIDATE_BOOLEAN,
                             array('flags' => FILTER_NULL_ON_FAILURE));
    return $ret;
}
$var = filter_var('yes', FILTER_CALLBACK, array('options' => 'foo'));
?>

http_build_query

<?php
$data = array('foo', 'bar', 'baz', 'boom',
              'cow' => 'milk',
              'php' =>'hypertext processor');

echo http_build_query($data) . "\n";
echo http_build_query($data, 'myvar_');
?>
<?php
$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data);
    // foo=bar&baz=boom&cow=milk&php=hypertext+processor
echo http_build_query($data, '', '&amp;');
    // foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor

?>
0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor
myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&php=hypertext+processor