PDA

View Full Version : مبتدی: تبدیل به شی گرا



fatima a
چهارشنبه 24 خرداد 1391, 12:44 عصر
سلام دوستان

من یه برنامه دارم که ساخت یافته است ، حالا میخوام شی گراش کنم

میشه اینو برام تبدیل کنید.

<?php
/*
* count specified character
* Date : 2012 - 04 - 20
* Author : fatima
* Ver : 1.0
* Todo : ---
*/


function char_count(&$parameters)
{
$totalSize = strlen($parameters['myString']);
$parameters['count'] = 0;
$parameters['pos'] = array();
for($index = 0; $index < $totalSize ; $index ++)
{
if(substr($parameters['myString'], $index , 1) == $parameters['char'])
{
$parameters['count']++;
$parameters['pos'][] = $index;

}

}


}

/*
* end of function
*/


$myString="It's a test . we want to find the sentences ends. If you can right the right function.";

$input=array('myString'=>$myString,
'char'=>'.',
);
char_count($input) ;



echo $myString."<br/>";
echo "result: ". $input['count'];
echo "<br/>";
$gloe="";
echo 'position:';
foreach ($input['pos'] as $value )
{
echo $gloe.$value;
$gloe=',';
}




البته با توجه به این فایل
<?php
//************************************************** *********//
// File : Database Interface Class
// Author :fatima
// Date : 24 Nov 2008
// Time : 11:25
// Ver : 1.5
// changes : Add some extra standard function in order to reduce
// the usable code copy/paste.
//************************************************** *********//

class DbInterface {

//************************ Private Variables *************************//

private $db_host;
private $db_usr;
private $db_pass;
private $db_name;
private $db_conn;


private $query;
private $die_page;


//************************************************** *********//
// set data base configuration file
//************************************************** *********//
function __construct($file=""){
$this->setDbConfig($file);
}

//************************************************** *********//
// set data base configuration file
//************************************************** *********//
function setDbConfig($file){


if (strlen(trim($file))>0) {

require_once ($file);

$this->db_host=$db_host;
$this->db_usr=$db_user;
$this->db_pass=$db_password;
$this->db_name=$db_name;
$GLOBALS['siteAdd'] = $siteAdd;
$GLOBALS['dynamicContentPath'] = $dynamicContentPath;

}
}

//************************************************** *********//
// Set Query Method
//************************************************** *********//
function setQuery($query){
$this->query=$query;
}

//************************************************** *********//
// Set Die Page Method
//************************************************** *********//

function setDiePage($page){
$this->die_page=$add;

}

//************************************************** *********//
// redirect method on die connection
//************************************************** *********//
function redirect(){
return( "<script type=\"text/javascript\" >window.location=\"".$this->die_page."\"</script>");
}

//************************************************** *********//
// Get Query base on configured variables
//************************************************** *********//
function getQuery($select=1){

if ($select==1){
return(@ $this->fetchArray());
}
else {
return(@ $this->runQuery());
}
}

//************************************************** *********//
// Run Insert/Delete/update base on configured variables
//************************************************** *********//
function runQuery(){

mysql_select_db($this->db_name, $this->db_conn);
$result = mysql_query($this->query, $this->db_conn);
return ($result);
}

//************************************************** *********//
// Run Select Queries
//************************************************** *********//
function fetchArray(){

mysql_select_db($this->db_name, $this->db_conn);
$result = mysql_query($this->query, $this->db_conn);
$data = array();
while ($row = mysql_fetch_assoc($result)){
$data[] = $row;
}
mysql_free_result($result);
return $data;
}

//************************************************** *********//
// connecting to database and set handler
//************************************************** *********//
function connectDb(){

if ($this->die_page!=''){
$this->db_conn = mysql_connect($this->db_host, $this->db_usr, $this->db_pass) or die($this->redirect());
}
else{
$this->db_conn = mysql_connect($this->db_host, $this->db_usr, $this->db_pass) or die("Error! <br /> connection failed!");
}

}

//************************************************** *********//
// connecting to database and set handler
//************************************************** *********//
function swPersian(){
$this->setQuery("set names 'utf8'");
$iResult=$this->getQuery(0);
return($iResult);
}

/**
* Update Query : Standard
* - base on input field and values
* Parameter :
* $table :table name
* $keyField : use in where clause to specify the record to be update
* $keyValue : value of above field
* $fieldValues : set of filed and related values that should be update
**/
function updateQuery($table,$keyField,$keyValue,$fieldValue s=null){
if (!empty($fieldValues) && is_array($fieldValues)){
$updateString="SET ";
$comma=",";
foreach ($fieldValues as $key=>$value){
$updateString .= $key . "=" . $value;
}
$qry= "update $table " . $updateString . " where $keyField=$keyValue";
$this->setQuery($qry);
$reult = $this->getQuery(false);
return ($result);
}
else{
return(false);
}


}

/**
* Load Data : Standard
* - base on input field and values
* Parameter :
* $table :table name
* $filter : set of key and values which filter the result
* @return : first filterd record
**/
function loadData($table,$filter = null){

$whereClause = "";
$comma = "";
if (!empty($filter))
{
foreach ($filter as $key=>$value)
{
$whereClause .= $comma . " `$key` = '$value' ";
$comma = " AND ";
}

$whereClause = ' where ' . $whereClause ;
}
$qry= "select * from $table" . $whereClause;

$this->setQuery($qry);
$result = $this->getQuery(true);
if (!empty($result))
{
return ($result[0]);
}
else
{
return (false);
}

}

/**
* Get Data : Standard
* - base on input field and values
* Parameter :
* $table :table name
* $filter : set of key and values which filter the result
* @return : first filterd record
**/
function getData($table,$filter = null){

$whereClause = "";
$comma = "";
if (!empty($filter))
{
foreach ($filter as $key=>$value)
{
$whereClause .= $comma . " `$key` = '$value' ";
$comma = " AND ";
}

$whereClause = ' where ' . $whereClause ;
}
$qry= "select * from $table" . $whereClause;
$this->setQuery($qry);
$result = $this->getQuery(true);
if (!empty($result))
{
return ($result);
}
else
{
return (false);
}

}


/**
* Count Data : Specific
* - base on input field and values
* Parameter :
* $table :table name
* $filter : set of key and values which filter the result
* @return : the number of available rows
**/
function countData($table,$filter = null , $like = false , $logic = 'AND'){

$whereClause = "";
$comma = "";
$operator = $like==true ? 'like':'=';
$added = $like==true ? '%':'';

if (!empty($filter))
{
foreach ($filter as $key=>$value)
{
$whereClause .= $comma . " `$key` $operator '" .$added.$value.$added."' ";
$comma = " $logic ";
}
$whereClause = ' where ' . $whereClause ;
}
$qry= "select count(*) as aghdas from $table" . $whereClause;
$this->setQuery($qry);
$result = $this->getQuery(true);
if (!empty($result))
{
return ($result[0]['aghdas']);
}
else
{
return (false);
}

}

//************************************************** *********//
// Get Last Inserted Item
//************************************************** *********//
function getLastInsertID(){
$qry="select last_insert_id() as id";
$this->setQuery($qry);
$result = $this->getQuery(true);
return ($result[0]['id']);
}

//************************************************** *********//
// close connection to databaase
//************************************************** *********//
function closeDb(){
mysql_close($this->db_conn);
}

//************************ class Ends *************************//
}
?>

fatima a
چهارشنبه 24 خرداد 1391, 16:39 عصر
کسی نمیتونه کمکم کنه؟ :(