PHP . SU
Программирование на PHP, MySQL и другие веб-технологии
Страниц (1): [1]
Найдено сообщений: 11
Jason Bourne
Отправлено: 12 Января, 2013 - 19:31:06 • Тема: Странное поведение CURL • Форум: Если скрипт не работает
Ответов: 4 Просмотров: 1162
В одном проекте необходимо парсить сайт, запрашивая одну или несколько страниц. После нескольких запросов сайт перестал загружаться. Хотя он грузится через браузер и через CURL другим скриптом. Причем у обоих скриптов одинаковые параметры curl_setopt .
С чем это может быть связано?
Jason Bourne
Отправлено: 06 Октября, 2011 - 06:43:55 • Тема: Вложенные блоки IF в шаблонизаторе • Форум: Напишите за меня, пожалуйста
Ответов: 0 Просмотров: 30
Работаю над одним стороннем скрипте, в нем есть обработчик шаблонов.
Вот его функция, которая непосредственно занимается обработкой шаблона.
PHP:
скопировать код в буфер обмена
/*************************************************************************
* function CreatePageEcho ()
* Echos the finished template
* USAGE example:
* $page->CreatePageEcho();
* ***********************************************************************/
function CreatePageEcho ( $lang , $config )
{
global $settings_tpl ;
$lang [ 'BUYERU' ] = $settings_tpl [ 'buyers_title' ] ;
$lang [ 'PROVIDERU' ] = $settings_tpl [ 'providers_title' ] ;
if ( count ( $comment_matches [ '0' ] ) != 0
) {
foreach ( $comment_matches [ '0' ] as $key => $value )
{
}
}
foreach ( $settings_tpl as $key => $value ) $this -> html = str_replace ( "{TPL." . $key . "}" , $value , $this -> html ) ;
foreach ( $lang as $key => $value )
{
$template_name = '{LANG_' . $key . '}' ;
$this -> html = str_replace ( $template_name , $value , $this -> html ) ; }
foreach ( $this -> parameters as $key => $value )
{
$template_name = '{' . $key . '}' ;
$this -> html = str_replace ( $template_name , $value , $this -> html ) ; }
$this -> html = str_replace ( '{SITE_URL}' , $config [ 'site_url' ] , $this -> html ) ; $this -> html = str_replace ( '{TPL_NAME}' , $config [ 'tpl_name' ] , $this -> html ) ; $this -> html = str_replace ( '{CURRENCY_SIGN}' , $config [ 'currency_sign' ] , $this -> html ) ; $this -> html = str_replace ( '{CURRENCY_CODE}' , $config [ 'currency_code' ] , $this -> html ) ; $this -> html = str_replace ( '{CURRENCY_POS}' , $config [ 'currency_pos' ] , $this -> html ) ;
if ( isset ( $_SESSION [ 'user' ] [ 'id' ] ) ) {
$this -> html = str_replace ( '{LOGGED_IN}' , '1' , $this -> html ) ; }
else
{
$this -> html = str_replace ( '{LOGGED_IN}' , '0' , $this -> html ) ; }
if ( isset ( $config [ 'temp_php' ] ) ) {
if ( $config [ 'temp_php' ] )
{
}
}
/*$ifmatches = array();
while(preg_match('/IF\(\"(.*?)\"(.*?)\"(.*?)\"\)\{([^\{]*?)\{:IF\}/s', $this->html, $ifmatches))
{
print_r($ifmatches);//foreach ($ifmatches['0'] as $key => $value)
{
if(trim($ifmatches['2']) == '!=')
{
if($ifmatches['1'] != $ifmatches['3'])
{
$this->html = str_replace($ifmatches['0'], $ifmatches['4'], $this->html);
}
else
{
$this->html = str_replace($ifmatches['0'], '', $this->html);
}
}
elseif(trim($ifmatches['2']) == '==')
{
if($ifmatches['1'] == $ifmatches['3'])
{
$this->html = str_replace($ifmatches['0'], $ifmatches['4'], $this->html);
}
else
{
$this->html = str_replace($ifmatches['0'], '', $this->html);
}
}
elseif(trim($ifmatches['2']) == '<')
{
if($ifmatches['1'] < $ifmatches['3'])
{
$this->html = str_replace($ifmatches['0'], $ifmatches['4'], $this->html);
}
else
{
$this->html = str_replace($ifmatches['0'], '', $this->html);
}
}
elseif(trim($ifmatches['2']) == '>')
{
if($ifmatches['1'] > $ifmatches['3'])
{
$this->html = str_replace($ifmatches['0'], $ifmatches['4'], $this->html);
}
else
{
$this->html = str_replace($ifmatches['0'], '', $this->html);
}
}
elseif(trim($ifmatches['2']) == '%')
{
$mod = $ifmatches['1']%$ifmatches['3'];
if($mod == 0)
{
$this->html = str_replace($ifmatches['0'], $ifmatches['4'], $this->html);
}
else
{
$this->html = str_replace($ifmatches['0'], '', $this->html);
}
}
}
}*/
preg_match_all ( '/IF\(\"(.*?)\"(.*?)\"(.*?)\"\)\{(.*?)\{:IF\}/s' , $this -> html , $ifmatches ) ; //while(preg_match_all('/IF\(\"(.*?)\"(.*?)\"(.*?)\"\)\{(.*?)\{:IF\}/s', $this->html, $ifmatches))
if ( count ( $ifmatches [ '0' ] ) != 0
) {
foreach ( $ifmatches [ '0' ] as $key => $value )
{
if ( trim ( $ifmatches [ '2' ] [ $key ] ) == '!=' ) {
if ( $ifmatches [ '1' ] [ $key ] != $ifmatches [ '3' ] [ $key ] )
{
$this -> html = str_replace ( $value , $ifmatches [ '4' ] [ $key ] , $this -> html ) ; }
else
{
}
}
elseif ( trim ( $ifmatches [ '2' ] [ $key ] ) == '==' ) {
if ( $ifmatches [ '1' ] [ $key ] == $ifmatches [ '3' ] [ $key ] )
{
$this -> html = str_replace ( $value , $ifmatches [ '4' ] [ $key ] , $this -> html ) ; }
else
{
}
}
elseif ( trim ( $ifmatches [ '2' ] [ $key ] ) == '<' ) {
if ( $ifmatches [ '1' ] [ $key ] < $ifmatches [ '3' ] [ $key ] )
{
$this -> html = str_replace ( $value , $ifmatches [ '4' ] [ $key ] , $this -> html ) ; }
else
{
}
}
elseif ( trim ( $ifmatches [ '2' ] [ $key ] ) == '>' ) {
if ( $ifmatches [ '1' ] [ $key ] > $ifmatches [ '3' ] [ $key ] )
{
$this -> html = str_replace ( $value , $ifmatches [ '4' ] [ $key ] , $this -> html ) ; }
else
{
}
}
elseif ( trim ( $ifmatches [ '2' ] [ $key ] ) == '%' ) {
$mod = $ifmatches [ '1' ] [ $key ] % $ifmatches [ '3' ] [ $key ] ;
if ( $mod == 0)
{
$this -> html = str_replace ( $value , $ifmatches [ '4' ] [ $key ] , $this -> html ) ; }
else
{
}
}
}
}
echo $this -> html ;
}
Сам шаблон выглядит примерно так:
CODE (
html ):
скопировать код в буфер обмена
{OVERALL_HEADER}
<table width = "780" border = "0" align = "center" cellpadding = "0" cellspacing = "0" >
<tr >
<td ><br >
<span class = "title1" > {LANG_PROJECTSU}</ span ><br / ><br >
<table width = "100%" cellpadding = "0" cellspacing = "1" border = "0" class = "table_titles" >
<tr bgcolor = "#E1E1E1" align = "center" >
<td width = "40%" align = "left" height = "18" style = "padding-left:5px;" > {LANG_PROJNAME}</ td >
<td width = "6%" bgcolor = "#E1E1E1" > {LANG_BIDS}</ td >
<td width = "30%" align = "left" style = "padding-left:5px;" > {LANG_JOBTYPE}</ td >
<td width = "12%" > {LANG_STARTED}</ td >
<td width = "12%" > {LANG_ENDS}</ td >
</ tr >
{LOOP: PROJECTS}
<tr align = "center" >
<td align = "left" style = "padding-left:5px;" ><a href = "{PROJECTS.link}" > {PROJECTS.title}</ a > IF("{PROJECTS.featured}"=="1"){ <span class = "featured" > {LANG_FEATURED}</ span > {:IF} IF("{PROJECTS.urgent}"=="1"){ <span class = "urgent" > {LANG_URGENT}</ span > {:IF}</ td >
<td > {PROJECTS.bids}</ td >
<td align = "left" style = "padding-left:5px;" > {PROJECTS.types}</ td >
<td > {PROJECTS.startdate}</ td >
<td > {PROJECTS.enddate}</ td >
</ tr >
<tr >
<Td colspan = "5" background = "templates/{TPL_NAME}/images/hline_dot.gif" ><img src = "templates/{TPL_NAME}/images/dot.gif" width = "1" height = "1" alt = "" border = "0" ></ TD >
</ tr >
{/LOOP: PROJECTS}
<tr >
<td colspan = "5" ><br >
<br ></ td >
</ tr >
</ table >
</ td >
</ tr >
</ table >
{OVERALL_FOOTER}
Собственно, блок IF выглядит так:
Однако, он может быть только одного уровня. Как можно переделать эту функцию, чтобы можно было использовать несколько уровней?
А вот моя попытка:
PHP:
скопировать код в буфер обмена
while ( preg_match ( '/IF\(\"(.*?)\"(.*?)\"(.*?)\"\)\{([^\{]*?)\{:IF\}/s' , $this -> html , $ifmatches ) ) {
print_r ( $ifmatches ) ; //foreach ($ifmatches['0'] as $key => $value) {
if ( trim ( $ifmatches [ '2' ] ) == '!=' ) {
if ( $ifmatches [ '1' ] != $ifmatches [ '3' ] )
{
$this -> html = str_replace ( $ifmatches [ '0' ] , $ifmatches [ '4' ] , $this -> html ) ; }
else
{
$this -> html = str_replace ( $ifmatches [ '0' ] , '' , $this -> html ) ; }
}
elseif ( trim ( $ifmatches [ '2' ] ) == '==' ) {
if ( $ifmatches [ '1' ] == $ifmatches [ '3' ] )
{
$this -> html = str_replace ( $ifmatches [ '0' ] , $ifmatches [ '4' ] , $this -> html ) ; }
else
{
$this -> html = str_replace ( $ifmatches [ '0' ] , '' , $this -> html ) ; }
}
elseif ( trim ( $ifmatches [ '2' ] ) == '<' ) {
if ( $ifmatches [ '1' ] < $ifmatches [ '3' ] )
{
$this -> html = str_replace ( $ifmatches [ '0' ] , $ifmatches [ '4' ] , $this -> html ) ; }
else
{
$this -> html = str_replace ( $ifmatches [ '0' ] , '' , $this -> html ) ; }
}
elseif ( trim ( $ifmatches [ '2' ] ) == '>' ) {
if ( $ifmatches [ '1' ] > $ifmatches [ '3' ] )
{
$this -> html = str_replace ( $ifmatches [ '0' ] , $ifmatches [ '4' ] , $this -> html ) ; }
else
{
$this -> html = str_replace ( $ifmatches [ '0' ] , '' , $this -> html ) ; }
}
elseif ( trim ( $ifmatches [ '2' ] ) == '%' ) {
$mod = $ifmatches [ '1' ] % $ifmatches [ '3' ] ;
if ( $mod == 0)
{
$this -> html = str_replace ( $ifmatches [ '0' ] , $ifmatches [ '4' ] , $this -> html ) ; }
else
{
$this -> html = str_replace ( $ifmatches [ '0' ] , '' , $this -> html ) ; }
}
}
}
И не получилось.
Весь шаблонизатор во вложенном файле.
Jason Bourne
Отправлено: 30 Июня, 2010 - 05:47:05 • Тема: Редакторы PHP • Форум: Программное обеспечение
Ответов: 421 Просмотров: 254699
Недостатки WeBuilder по сравнению с PHP Expert Editor:
1. Не запоминает, какие окна были открыты, и не восстанавливает их при следующем запуске (А может, это и плюс - открываются только необходимые файлы).
2. Не всегда корректно строит дерево навигации Code Explorer.
3. Нет подсказок с отображением параметров функции.
Плюсы:
1) Автозавершение пользовательских функций.
2) Expert Editor регулярно вылетает
Jason Bourne
Отправлено: 14 Октября, 2009 - 05:07:10 • Тема: Редакторы PHP • Форум: Программное обеспечение
Ответов: 421 Просмотров: 254699
PHP Expert Editor - хороший редактор, но не нравятся следующие вещи:
* Поиск по тексту не очень хороший, а именно - криво работает команда "искать дальше"
* Вылетает периодически (причем так происходит на ДВУХ компьютерах, на которых я работаю, один из которых - не самый слабый)
* Немного весит, однако долго запускается
Jason Bourne
Отправлено: 13 Октября, 2009 - 20:27:21 • Тема: Письма отправляются много раз • Форум: Программирование на PHP
Ответов: 9 Просмотров: 684
В одном проекте рассылаются уведомления на список адресов, которые берутся из базы данных.
Код отправки примерно такой:
Цитата: $q = 'select * from hl_maillist';
$sth = mysql_query($q) or die(mysql_error());
while($row = mysql_fetch_array($sth))
{
/*Здесь код формирования письма*/
mail($row['email'],"New HYIP is added in G.S. Monitor",$message,"Content-type: text/html; charset=windows-1251\nFrom: ".$settings['admin_email']);
}
И почему-то приходит иногда по пять одинаковых писем на один адрес, а иногда и больше.
Проверял - каждый адрес присутствует в базе данных один раз.
Почему такое может быть?
И как только я не колдовал над этим кодом, и задержку добавлял, и в очередь письма добавлял - проблема не решается, хоть ты тресни - приходят два письма, иногда даже три.
Страниц (1): [1]
Powered by ExBB FM 1.0 RC1. InvisionExBB