Archive

Check URL without downloading the body

public function url_exists($url) { $handle = curl_init($url); if (false === $handle) { return false; } curl_setopt($handle, CURLOPT_HEADER, false); curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works curl_setopt($handle,

Read More »

Normalize special characters

public function normaliza($string) { $normalizeChars = array( ‘Š’ => ‘S’, ‘š’ => ‘s’, ‘Ð’ => ‘Dj’, ‘Ž’ => ‘Z’, ‘ž’ => ‘z’, ‘À’ => ‘A’,

Read More »

Add href inside string

public function str2href($str) { $str = preg_replace(‘/s(w+://)(S+)/’, ‘ <a href=”\1\2″ target=”_blank”>\1\2</a>’, $str); }

Read More »

Highlight matching keyword in a string

public function str_highlight($text, $needle = ”, $options = null, $highlight = null) { $STR_HIGHLIGHT_SIMPLE = 1; $STR_HIGHLIGHT_WHOLEWD = 2; $STR_HIGHLIGHT_CASESENS = 0; $STR_HIGHLIGHT_STRIPLINKS = 8;

Read More »

Flatten array

? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 public function array_flatten($a, $f = array()) {     if (!$a

Read More »

Compare string by array

function stristr_array($string, $needleArray) { if (!is_array($needleArray)) { return false; } if (is_array($needleArray) && count($needleArray)) { foreach ($needleArray as $needle) { if (stristr($string, $needle)) { return

Read More »

Sort array by key (human order)

function natksort(&$array) { $keys = array_keys($array); natcasesort($keys); if (is_array($keys) && count($keys)) { foreach ($keys as $k) { $new_array[$k] = $array[$k]; } } $array = $new_array;

Read More »

HEX to RGB

function hex2rgb($hex) { if ($hex) { $hex = str_replace(‘#’, ”, $hex); if (strlen($hex) == 3) { $r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1));

Read More »

Convert MySQL column names to PHP array

function getTableColumnNames($table) { if ($table) { $query = “SHOW COLUMNS FROM ” . $table; $res = $GLOBALS[‘TYPO3_DB’]->sql_query($query); $fields = array(); while ($row = $GLOBALS[‘TYPO3_DB’]->sql_fetch_assoc($res)) {

Read More »

Most Popular