سلام. ممنون دوست عزیز. دراین مورد یه توضیحی میدین ؟ منظور از این دکد کردن برای عکس چیه؟ و اینکه تو مثالها دیدم که نوشته بودید تبدیل کد عکس به کد اسکی آیا راه برعکسش وجود داره ؟
Printable View
اینجا اومده و عکس رو هچ کرده و به صورت رمزی در آورده و برای اینکه از encode در بیاریم باید از decode استفاده کنیم
بسم الله الرحمن الرحیم
سلام
تابع mysql_list_tables - ن deprecated شده بهتره ازش استفاده نکنی
بجاش می تونید از کوئری زیر برای لیست جدول ها استفاده کنی:
"show tables;"
validation ساده برای داده های فرم
<?php
class Validation
{
public $errors = array();
public function isValidStr($strVal, $strType, $minChar=2, $maxChar = 1000) {
if(strlen($strVal) < intval($minChar)) {
$this -> setError($strType, ucfirst($strType)." must be at least {$minChar} characters long.");
} elseif (strlen($strVal) > intval($maxChar)) {
$this -> setError($strType, ucfirst($strType)." must be less than {$maxChar} characters long.");
} else {
// validate data entry
$pattern = "#^[\s\x{0621}-\x{063A}\x{0640}-\x{0691}\x{0698}-\x{06D2}\x{06F0}-\x{06F9}\x{0661}-\x{0669}0-9\n\r\\'\-\_\.\:\,0-9a-zA-Z]+$#u";
if (!preg_match($pattern, $strVal)) {
$this -> setError($strType, ucfirst($strType)." must be from letters, dashes, spaces and must not start with dash");
}
}
}
public function isValidEmail($emailVal) {
if(strlen($strVal) < 0 ) {
$this -> setError('email', 'E-mail Address cannot be blank');
} else {
// validate data entry
$pattern = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";
if (!preg_match($pattern, $emailVal)) {
$this -> setError('email', 'Please enter valid E-mail Address');
}
}
}
public function isValidURL($urlVal) {
if(!empty($urlVal)) {
$pattern = "#^http(s)?://[a-z0-9-_.]+\.[a-z]{2,4}#i";
if (!preg_match($pattern, $urlVal)) {
$this -> setError('url', 'Please enter valid URL Address with http://');
}
}
}
public function setError($key, $value) {
$this -> errors[$key] = $value;
}
public function getError($key) {
if ($this -> errors[$key]) {
return $this -> errors[$key];
} else {
return false;
}
}
public function errCount() {
return (count($this -> errors) > 0) ? count($this -> errors) : false;
}
}
?>
کلاسی برای ساخت Log file
<?php
class Log
{
private $_FileName;
private $_Data;
/**
* @desc Write to a file
* @param str $strFileName Then name of the file
* @param str $strData Data to be append to the file
*/
public function Write($strFileName, $strData)
{
// Set Class Vars
$this -> _FileName = $strFileName;
$this -> _Data = $strData;
// Check Data
$this -> _CheckPermission();
$this -> _CheckData();
$handle = fopen($strFileName, 'a+');
fwrite($handle, $strData."\r");
}
/**
* @desc Read from a file
* @param str $strFileName Then name of the file
* @return str The text file
*/
public function Read($strFileName)
{
$this -> _FileName = $strFileName;
$this -> _CheckExists();
$handle = fopen($strFileName, 'r');
return file_get_contents($strFileName);
}
private function _CheckExists()
{
if (!file_exists($this -> _FileName))
die ('The file does not exists');
}
private function _CheckPermission()
{
if (!is_writable($this -> _FileName))
die ('Change you CHMOD permission to '.$this -> _FileName);
}
private function _CheckData()
{
if (strlen($this -> _Data) < 1)
die ('You must have more than one character to write on the file');
}
}
?>
یک کلاس جالب برای اتصال به بانک داده ها
<?php
// Using OOP PHP to select, update, and insert data in a mysql database
class database
{
private $dbhost;
private $dbuser;
private $dbpass;
private $dbname;
private static $instance;
private $connection;
private $results;
private $numRows;
private function __construct() {}
static function getInstance()
{
if(!self::$instance)
{
self::$instance = new self();
}
return self::$instance;
}
// Create Connection to MySQL
function connect($dbhost, $dbuser, $dbpass, $dbname)
{
$this -> dbhost = $dbhost;
$this -> dbuser = $dbuser;
$this -> dbpass = $dbpass;
$this -> dbname = $dbname;
$this -> connection = mysqli_connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
}
// Run Query
public function doQuery ($sql)
{
$this -> results = mysqli_query($this -> connection, $sql);
$this -> numRows = $this -> results -> num_rows;
}
// Load the list of data in database
public function loadObjectList()
{
$obj = 'No Results';
if ($this -> results)
{
$obj = mysqli_fetch_assoc($this -> results);
}
return $obj;
}
}
?>
نمونه برنامه موتور جستجو
دوستان من اين برنامه رو اينجا قرار مي دم تا دوستان ازش بتونن استفاده كنند
فقط من بحث هاي امنيتي رو لحاظ نكردم
//////////
//////////
فشرده كردن فضاهاي خالي غير ضروري:
$busca = array('/\>[^\S ]+/s','/[^\S ]+\</s','/(\s)+/s');
جدا كردن اعداد از يك رشته عبارت:
$busca = array('/\>[^\S ]+/s','/[^\S ]+\</s','/(\s)+/s');
//-------------------------
Example:
?d=52;d;s;s'2233l'[[22
Outpt:
Cleared value: 52223322
//////////
جلوگیری از اجرای اسکریپتهایی که باید include بشن:
این کد رو ابتدای اسکریپتهایی که میخواین مستقیماً قابل اجرا نباشن اضافه کنید تا فقط بشه اونها رو require کرد:
$script = pathinfo($_SERVER['SCRIPT_FILENAME'], PATHINFO_BASENAME);
$file = pathinfo(__FILE__, PATHINFO_BASENAME);
if($script == $file) {
header('location: index.php');
exit();
}
البته اینم میشه :
if(realpath($_SERVER['SCRIPT_FILENAME']) == realpath(__FILE__)) {
header('location: index.php');
exit();
}
//////////
البته کلاس هم مزایای خاص خودش رو داره. بخصوص مباحثی که مرتبط با Encapsulation و تعیین سطح دسترسی هست. بعلاوه میتونید Snippetهای مختلف رو توی یک کلاس با نام دلخواه قرار بدین و با ایجاد یک شئ از اون کلاس، به همه اونها دسترسی پیدا کنید. حتی میتونید اونها رو از نوع static تعریف کنید که دیگه نیازی به ساخت شئ هم نباشه. بحث وراثت که وسط میاد، قدرت اصلی شئ گرایی توش مشخص میشه. درمورد Interfaceها و کلاسهای Abstract و... هم که بهتره صحبت نکنیم چون فکر نمیکنم دیگه کسی باقی بمونه که بخواد از روش رَویه گرا (Procedural) استفاده کنه و همه بسمت OOP حرکت کنن. البته باز هم تأکید میکنم شئ گرایی یک امتیازه نه یک اجبار و از این جهت، PHP خیلی خوب تونسته تعادل مناسبی بین برنامه نویسی Procedural و Object Oriented برقرار کنه. موفق باشید.
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
//////////
اين هم يك تكه كد واقعا به درد بخور
function wordsub($string,$len=10,$str2='...')
{
$array=explode(' ',$string,$len+1);
array_pop($array);
return implode(' ',$array).' '.$str2;
}
كار اين تك كد اينه كه شما يك رشته رو بهش پاس مي دين و مي گيد كه مثلا n تا كلمه اول رو جدا كنه و به جاي بقيه پارامتر سوم رو بذاره
اسنیپت یعنی "قعطه کد" .
اینجا هم یه سری بزنید :
http://phpsnips.com/
باسلام:
ارسال ایمیل با کاراکترهای فارسی.....!
//////////
//////////
تبدیل عکس به متن
موفق باشید.کد HTML:<!doctype html>
<html>
<head>
<title>ASCII Image</title>
</head>
<body>
<?php
function ascii_image($image) {
$result = '';
if(file_exists($_GET['image'])) {
if(substr($image, strrpos($image, '.')) == '.jpg') {
$img = imagecreatefromjpeg($image);
$result .= '<style type="text/css">'.PHP_EOL;
$result .= '.ascii_image {'.PHP_EOL;
$result .= 'font-family: Tahoma;'.PHP_EOL;
$result .= 'font-size: 1px;'.PHP_EOL;
$result .= 'line-height: 1px;'.PHP_EOL;
$result .= '}'.PHP_EOL;
$result .= '</style>'.PHP_EOL;
$iw = imagesx($img);
$ih = imagesy($img);
$result .= '<div class="ascii_image">'.PHP_EOL;
for($h = 0; $h < $ih; $h++) {
for($w = 0; $w < $iw; $w++) {
$rgb = imagecolorat($img, $w, $h);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = ($rgb >> 0) & 0xFF;
$result .= '<span style="color: rgb('.$r.','.$g.','.$b.');">#</span>';
}
$result .= '<br/>'.PHP_EOL;
}
$result .= '</div>'.PHP_EOL;
}
else {
$result .= 'Wrong File Type';
}
}
return $result;
}
// How to use it ?
if(isset($_GET['image'])) {
echo ascii_image($_GET['image']);
}
?>
</body>
</html>
تبدیل عکسهای رنگی به سیاه و سفید:
<?php
header('Content-type: image/jpeg');
if(!isset($_GET['file']) || !file_exists($_GET['file']) || strtolower(substr($_GET['file'], strrpos($_GET['file'], '.'))) != '.jpg') {
$im = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefill($im, 50, 50, $white);
imagestring($im, 5, 30, 40, 'Error', $black);
imagejpeg($im);
imagedestroy($im);
exit();
}
$file = $_GET['file'];
list($width, $height) = getimagesize($file);
$source = imagecreatefromjpeg($file);
$bwimage = imagecreate($width, $height);
$palette = array();
for ($i = 0; $i < 256; $i++) {
$palette[$i] = imagecolorallocate($bwimage, $i, $i, $i);
}
for($y = 0; $y < $height; $y++) {
for($x = 0; $x < $width; $x++) {
$color = imagecolorat($source, $x, $y);
$r = ($color >> 16) & 0xFF;
$g = ($color >> 8) & 0xFF;
$b = ($color >> 0) & 0xFF;
$gs = ($r * 0.299) + ($g * 0.587) + ($b * 0.114);
imagesetpixel($bwimage, $x, $y, $palette[$gs]);
}
}
imagejpeg($bwimage);
imagedestroy($source);
imagedestroy($bwimage);
?>
مثال از نحوه فراخوانی:
امیدوارم این هم به درد بخورهکد HTML:<img src="bw.php?file=image.jpg"/>