Mehmet Mutlu

12 Mayıs 2011

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("‘", "’", "“", "”", "–", "—", "…"),
array("'", "'", '"', '"', '-', '--', '...'),
$text);

// Windows-1252 karakterleri cevir
$text = str_replace(
array("‘", "’", "“", "”", "–", "—", "…"),
array("'", "'", '"', '"', '-', '--', '...'),
$text);

// Turkce karakterleri cevir
$text = str_replace(
array("Ğ", "ğ", "Ö", "ö", "Ç", "ç", "Ş", "ş", "İ", "ı", "Ü", "ü"),
array("Ğ", "ğ", 'Ö', 'ö', 'Ç', 'ç', 'Ş', 'ş', 'İ', 'ı', 'Ü', 'ü'),
$text);

return $text;
}

07 Mayıs 2011

checkdate

etiketler: , , — 11:46
bool checkdate ( int $month , int $day , int $year )
<?php

$date = "01-01-1980 <script>alert('test');</script>";
$aDate_parts = preg_split("/[\s-]+/", $date);

var_dump(
    checkdate(
        $aDate_parts[1], // Month
        $aDate_parts[0], // Day
        $aDate_parts[2] // Year
    )
);

?>

preg_split

array preg_split ( string $şablon , string $konu [, int $sınır = -1 [, int $seçenekler = 0 ]] )
<?php
$string = 'one, two,three,     four  , five,six seven';
$array = preg_split("/[\s]*[,][\s]*/", $string);
print_r($array);
// Array ( [0] => one [1] => two [2] => three [3] => four [4] => five [5] => six seven )
?>

13 queries. 1,106 seconds. Creative Commons Alexa XHTML CSS Rss Google Site Map Mehmet Mutlu