2
I have the following fields in Array():
# Tratamento das variaveis para substituição da mensagem
$campos = array(
0 => '#celular',
1 => '#ddd',
2 => '#cpf_cnpj',
3 => '#nome_razaosocial',
4 => '#mensagem',
5 => '#cod_cliente',
6 => '#cod_contrato',
7 => '#cod_barras',
8 => '#valor_divida',
9 => '#telefone_r_1',
10 => '#telefone_r_2',
11 => '#telefone_r_3'
);
And I also have a variable:
$dados['mensagem'] = "Aqui mensagem #celular #ddd #cod_barras";
And I have the value of these tags, in the fingers bank, on the table files_fields
I need to check in $message if any of these available tags exist, and replace.
I tried it this way:
<?php
$sql_dados = mysqli_query($conn, "SELECT * FROM files_fields LIMIT 5");
while($row_dados=mysqli_fetch_assoc($sql_dados)){
?>
<tr>
<td><?php echo $row_dados['celular']; ?></td>
<td>
<?php
//foreach($campos_arr as $valor){
if(in_array($campos, $dados['mensagem'])){
$mensagem = str_replace($campos, $row_dados[$valor], $dados['mensagem']);
} else {
$mensagem = $_GET['mensagem'];
}
// echo $mensagem;
// }
?>
</td>
</tr>
<?php } ?>
But returns the following error:
Warning: in_array() expects Parameter 2 to be array, string Given in D: Sites Localhost Easyphp-Devserver-14.1VC11 data localweb dashboard-Wallace php gerarAmostra.php on line 46
How can I elaborate in the right way?
to check with
in_array
the second parameter must also be aarray
– RFL
$data['message'] = $_GET['message'];
– Sr. André Baill
I edited, the right way
– Sr. André Baill
It seems that call from
in_array()
is reversed anyway I think it will not give the expected result.– rray
$mensagem
has only hashtags?– rray
No $message can have message and hastag in between
– Sr. André Baill