Templates
Вот еще один правильный взгляд на шаблоны (курсив мой):
"I’m basically advocating a «template engine» that uses PHP code as it’s native scripting language. I know, this has been done before. When I read about it, I thought simply, «what’s the point?» After examining my co-worker’s argument and implementing a template system that uses straight PHP code, but still acheives the ultimate goal of separation of business logic from presentation logic (and in 40 lines of code!), I have realized the advantages and honestly, can probably never go back.While I think this method is far superior, there are of course some issues. The first argument against such a system (well, the first argument I would expect) is that PHP code is too complex, and that designers shouldn’t be bothered with learning PHP. In fact, PHP code is just as simple (if not moreso) as the syntax of the more advanced template engines (such as Smarty).
Надо писать по этому поводу заметку.
MySql vs Files
Ну, если про хранение текстовой информации еще можно поспорить — и совершенно справедливо — то некоторые вещи меня удивляют. Использовать MySql для хранения картинок... и выдавать их так...
$data = @mysql_result($result, 0, "imageinfouser");
header("Content-type: $type");
echo $data;
Мне даже сказать по этому поводу нечего.
Функция
Функция переводит относительные урлы в абсолютные.
Использование:
$text=R_absurl ($text, $host);
где $host — адрес вашего сайта.
{ function R_absurl ($text, $host)
function R_au ($url, $host)
if (stristr ($url, "://")) return $url;
if (stristr ($host, "://")) $host=substr ($host, strpos ($host, "://")+3);
$url=$host."/".$url;
$url=str_replace ("/./", "/", $url);
while (stristr ($url, "//")) $url=str_replace ("//", "/", $url);
while (preg_match ("//([^/.]{1,})/..//", $url)) $url=preg_replace ("//([^/.]{1,})/..//", "/", $url);
$url="http://".$url;
return $url;
}
{
$text=preg_replace ("/(href=http://nudnik.ru/["]{0,1})([^ ">]*)/ie", "'\1'.R_au('\2', $host)", $text);
$text=preg_replace ("/(src=http://nudnik.ru/["]{0,1})([^ ">]*)/ie", "'\1'.R_au ('\2', $host)", $text);
$text=stripslashes ($text);
return $text;
}