本文整理汇总了PHP中Chat::listar方法的典型用法代码示例。如果您正苦于以下问题:PHP Chat::listar方法的具体用法?PHP Chat::listar怎么用?PHP Chat::listar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chat
的用法示例。
在下文中一共展示了Chat::listar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Chat
<?php
require 'config/config.php';
$chat = new Chat();
switch ($_POST['acao']) {
case 'inserir':
$chat->excluir();
$chat->setUsuario($_COOKIE['usuario']);
$chat->setMensagem(filter_input(INPUT_POST, 'mensagem'));
if ($chat->inserir()) {
printf('<p class="ativo">[%s] - %s</p>', $chat->getUsuario(), $chat->getMensagem());
}
break;
case 'atualizar':
foreach ($chat->listar() as $value) {
$ativo = $value->usuario == $_COOKIE['usuario'] ? ' class="ativo"' : '';
printf('<p%s><strong>%s</strong> - %s<br>%s</p>', $ativo, $value->usuario, $value->datahora, $value->mensagem);
}
break;
}
示例2: array
<?php
class Chat
{
public static $conectados = array();
public $nome;
public function __construct($nome)
{
$this->nome = $nome;
Chat::$conectados[] = $this;
}
public static function listar()
{
return Chat::$conectados;
}
}
new Chat("Frank");
new Chat("Joao");
new Chat("Pedro");
print_r(Chat::listar());
示例3: printf
</head>
<body>
<div class="content-fluid">
<h1 class="text-center">Bem vindo ao nosso chat</h1>
<p class="text-center text-success">
Nome de Usuário: <strong><?php
echo $_COOKIE['nome'];
?>
</strong>
</p>
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"></div>
<div name="painel_chat" id="painel" class="col-xs-10 col-sm-10 col-md-10 col-lg-10 text-center bg-info" style="margin-top:20px;max-height:390px; overflow-x:auto;">
<?php
foreach ($chat->listar() as $v) {
$ativo = $v['nome'] == $_COOKIE['nome'] ? 'class="bg-primary eu pull-right"' : 'class="bg-warning ele pull-left;"';
printf('<br><p %s> %s Disse: " %s "</p><br>', $ativo, $v['nome'], $v['mensagem']);
}
?>
</div>
<div name="box_digitar" id="digitar" class="col-xs-12 col-sm-12 col-md-12 col-lg-12 text-center bg" style="margin-top:20px">
<form action="" method="post" id="frm-msg">
<div class="form-group">
<label>
<span>Mensagem:</span>
<input name="mensagem" id="mensagem" class="form-control">
</label>