Archive for the 'PHP' Category
Kommentek eltavolitasa HTML kodbol
Ez egy egyszeru funkcio, amely parameterben egy szoveget var. Kimenetkepp visszaadja a szoveget ugy, hogy kitorli belole a HTML kommenteket.
„<!– ….. –>”
<?php
function remove_comments($s) {
return preg_replace('/<!--(.+?)-->/s', '', $s);
}
Comments are off for this post
Tomb atirasa „array” formaba
<?php
$testarr = array(1, 2, "3", 5);
function escape($s)
{
if (is_string($s))
return "'".$s."'";
else
return $s;
}
function array2php($arr, $deep = 0)
{
if (!is_array($arr))
return "";
if (array_keys($arr) == array_keys(array_fill(0,count($arr), true)))
$keys = false;
else
$keys = true;
$ret = "array(";
foreach ($arr as $k => $v)
$ret .= ($keys ? escape($k)." => " : "").(is_array($v) ? array2php($v, $deep+1) : escape($v)).", ";
$ret = substr($ret, 0, -2);
$ret .= ")";
if ($deep == 0)
$ret .= ";";
return $ret;
}
print array2php($testarr);
?>
Comments are off for this post