Jump to content
php.lv forumi

class


Mikijs

Recommended Posts

Problema =/ itka ar klasi viss kartiba, bet kkas nav

 

Class

<?
class smileys {
 function smile($x)
 {
return "<img src='dizains/emoticons/$x.png'>";
 }
 function smileys($x)
 {
$x=str_replace(":)", smile("smile"), $x);
$x=str_replace(":(", smile("sad"), $x);
$x=str_replace(";)", smile("wink"), $x);
$x=str_replace(":D", smile("biggrin"), $x);
$x=str_replace(";(", smile("cry"), $x);
$x=str_replace("8)", smile("cool"), $x);
$x=str_replace("B)", smile("cool"), $x);
$x=str_replace(":@", smile("mad"), $x);
return $x;
 }
}
?>

 

=/ PHP

<?
$htmlbody="Mans :) Teksts :D Ko :@ Es B) Gribu :P Parveidot";

$htmlbody2=new smileys;
$htmlbody=$htmlbody2->smileys($htmlbody);
?>

Link to comment
Share on other sites

Nekas tev tur nav kārtībā. Tev vispār klasi nemaz nevajag izmantot.

 

Enīvei - tu apzinies, ka smileys() metode izsaucas arī tajā brīdī, kad izveido objektu ?

Un ko klases iekšienes klases metodes jāizsauc šādi: $this->metode();

Edited by andrisp
Link to comment
Share on other sites

zinu , varu arii izmantot parastu funkciju, vnk ta ka man praktiski lapa ir sadalaita pa dalam un pietam pa klasem, lapu kopa tur 4 klases

 

mailbox

user

settings

security

 

domaju izveidot

entertainment

un tipa ieksa sabast smileys (sakt ar smileys) vnk lai viss ir ar klasem..

Link to comment
Share on other sites

Priekš kam Tev klasi šādai lietai? īsāk sakot, neloģiski Tev tur..

<?

class smileys {

 

function smile($x)

{

$x=str_replace(":)", "smile", $x); //klases metodi izsauc ar $this->klases_metode(); bet te nafig nevajag

$x=str_replace(":(", "sad", $x);

$x=str_replace(";)", "wink", $x);

$x=str_replace(":D", "biggrin", $x);

$x=str_replace(";(", "cry", $x);

$x=str_replace("8)", "cool", $x);

$x=str_replace("B)", "cool", $x);

$x=str_replace(":@", "mad", $x);

return "<img src='dizains/emoticons/$x.png'>";

}

}

?>

 

<?

$htmlbody="Mans :) Teksts :D Ko :@ Es B) Gribu :P Parveidot";

 

$smile_objekts=new smileys(); //shito var un vajag rejūzot

$htmlbody=$smile_objekts->smile($htmlbody);

?>

Edited by Kristabs
Link to comment
Share on other sites

×
×
  • Create New...