Jump to content


- - - - -

Наши разработки


  • You cannot reply to this topic
24 replies to this topic

#21 Эльказ

Эльказ

    PHP Specialist

  • Постояльцы
  • PipPipPipPipPipPip
  • 1,793 posts
  • Time Online: 5h 33m 54s

Posted 24 March 2008 - 07:43 AM

Нужно было данные из формата
дд.мм.гггг чч:мм:сс первести в UNIX формат (т.е количество секунд прошедших с 1.1.1970)

Syntax Highlighted Code: PHP
 
function fDate ($date){
$date = trim ($date);
$regxp = explode (" ", $date);
 
$years = $regxp[0];
$time = $regxp[1];
 
$anotherOne = explode (".", $years);
$day = $anotherOne[0];
$mounth = $anotherOne[1];
$year = $anotherOne[2];
 
$other = explode (":", $time);
$hh = $other[0];
$mm = $other[1];
$ss = $other[2];
 
return mktime ($hh,$mm,$ss,$mounth,$day,$year);
}
 


При желании можно добавить функционала, типа вместо : - /. Но для меня эта функция нужнее в таком виде использую в каждом проекте (потому что я дату всегда храню как integer).
  • 0

#22 Эльказ

Эльказ

    PHP Specialist

  • Постояльцы
  • PipPipPipPipPipPip
  • 1,793 posts
  • Time Online: 5h 33m 54s

Posted 10 May 2008 - 06:59 PM

Syntax Highlighted Code: PHP
 
public function SmileTransform ($text){
$SmilePath = Images . '/smiles';
$Glob = glob ($SmilePath . '\*.png');
 
for ($i = 0; $i < sizeof ($Glob); $i++){
$filename = basename ($Glob[$i]);
$text = str_replace (":".$filename.":", "<img src='".$Glob[$i]."' alt='Смайлик' title='Смайлик'>", $text);
}
 
return $text;
 
 
}
 


Вывести все .png файлы из папки и преобразовать их в картинку smile.gif
Смайлики, короче.

Edited by Elkaz, 10 May 2008 - 06:59 PM.

  • 0

#23 Эльказ

Эльказ

    PHP Specialist

  • Постояльцы
  • PipPipPipPipPipPip
  • 1,793 posts
  • Time Online: 5h 33m 54s

Posted 05 June 2008 - 12:40 PM

Syntax Highlighted Code: PHP
 
<?php

class DB {

public $Server;
public $Username;
public $Userpassword;
public $Database;
public $hadler;
public $query;
 
public function __construct ($Server, $Username, $Userpassword, $Database){
if (empty ($Server) || empty ($Username) || empty ($Database)){
throw new DBConnectException ("Can not connect to MySQL server... Some data is currently unavailable");
} else {
$DB_handler = @mysql_connect ($Server, $Username, $Userpassword);
if (!$DB_handler){
throw new DBConnectException ("Can not connect to MySQL server with following data");
}
 
if (!@mysql_select_db ($Database)){
throw new DBConnectException ("Can not select database [ connection established ]");
}
 
$this->handler = $DB_handler;
}
}
 
public function filter ($param){
return mysql_real_escape_string ($param);
}
 
private function build ($query, $params = array()){
$query = str_replace ('%', '%%', $query);
$query = str_replace ('?', '%s', $query);
 
$params = $this->prepare ($params);
 
return vsprintf ($query, $params);
}
 
private function prepare ($params){
if (is_array($params)) {
foreach ($params as &$param) {
$param = $this->prepare($param);
}
} else {
if (is_string($params)) {
return "'" . $this->filter($params) . "'";
} elseif (is_bool($params)) {
return $params ? true : false;
} elseif (is_null($params)) {
return 'NULL';
}
}
 
return $params;
}
 
public function result ($query){
return mysql_result ($query, 0, 0);
}
 
public function rows ($query){
return mysql_num_rows ($query);
}
 
public function fetch ($query){
$rows = array();
 
while ($row = mysql_fetch_assoc ($query)){
$rows[] = $row;
}
 
return $rows;
}
 
 
public function query ($query, $params = array()){
$query = $this->build ($query, $params);
$out = @mysql_query ($query, $this->handler);
if (!$out) throw new DBQueryException (mysql_error());
else return $out;
 
}
 
public function all ($query, $params = array()){
$handler = $this->query ($query, $params);
return $this->result ($handler);
}
 
 
 
 
}
 


Класс для работы с БД. Язык, естественно, PHP. СУБД - MySQL.
Класс еще не полностью дописан, но работать с ним можно уже сейчас вполне спокойно.

Syntax Highlighted Code: PHP
 
$this->DB->query ("UPDATE `".table_users."` SET email = ?, icq = ?, age = ?", array ($email, $icq, $age));
 

  • 0

#24 els

els

    Посетитель

  • Пользователи
  • PipPip
  • 86 posts
  • :

Posted 10 November 2008 - 07:38 AM

отправим маил

Код


public static void SendMail(
            string from ,
            string to,
            string subject,
            string body,
            bool unicode
            )
        {

            MailMessage msg = new MailMessage();
            msg.From = from;
            msg.To = to;
            msg.Subject = subject;
            msg.BodyFormat = MailFormat.Html;
            msg.Body = body;            
            if (unicode)
            {
                msg.BodyEncoding = System.Text.Encoding.UTF8;
            }


            if (ConfigurationSettings.AppSettings["smtpServer"] != null)
            {
                SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["smtpServer"];
            }

            SmtpMail.Send(msg);
        }


Edited by els, 10 November 2008 - 07:38 AM.

  • 0

#25 Эльказ

Эльказ

    PHP Specialist

  • Постояльцы
  • PipPipPipPipPipPip
  • 1,793 posts
  • Time Online: 5h 33m 54s

Posted 08 June 2009 - 11:33 AM

Для SEO порой бывает нужно сделать так, чтобы при заходе на http://site.ru было перенаправление на http://www.site.ru
Syntax Highlighted Code: PHP
 
<?php
// Перенаправление
if (!preg_match ("/www/", $_SERVER ['HTTP_HOST']){
header ('Location: http://www.akhundzade.ru');
exit;
}
?>
 

Edited by Elkaz, 08 June 2009 - 11:33 AM.

  • 0





0 user(s) are reading this topic

members, guests, anonymous users