<?php
$campos = [
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'
];
$valor = [
0 => '(19) 99999-9999',
1 => '999',
2 => '999.999.999-99',
3 => 'Teste de Razão Social',
4 => 'Obrigado por me testar',
5 => '99',
6 => '999',
7 => '99999999.99999999.99999999.9999999.9.9999999',
8 => '9.99',
9 => '(19) 99999-9999',
10 => '(19) 99999-9999',
11 => '(19) 99999-9999'
];
$dados['mensagem'] = 'Meu celular é #celular e meu código do cliente é #cod_cliente. Segue o código de barras: #cod_barras';
$mensagem = $dados['mensagem'];
foreach($campos as $key => $item){
if(strpos($dados['mensagem'], $item)){ $mensagem = str_replace($item, $valor[$key], $mensagem); }
}
echo $mensagem;
PD9waHAKCiRjYW1wb3MgPSBbCiAgIDAgID0+ICcjY2VsdWxhcicsCiAgIDEgID0+ICcjZGRkJywKICAgMiAgPT4gJyNjcGZfY25waicsCiAgIDMgID0+ICcjbm9tZV9yYXphb3NvY2lhbCcsCiAgIDQgID0+ICcjbWVuc2FnZW0nLAogICA1ICA9PiAnI2NvZF9jbGllbnRlJywKICAgNiAgPT4gJyNjb2RfY29udHJhdG8nLAogICA3ICA9PiAnI2NvZF9iYXJyYXMnLAogICA4ICA9PiAnI3ZhbG9yX2RpdmlkYScsCiAgIDkgID0+ICcjdGVsZWZvbmVfcl8xJywKICAgMTAgPT4gJyN0ZWxlZm9uZV9yXzInLAogICAxMSA9PiAnI3RlbGVmb25lX3JfMycKXTsKCiR2YWxvciA9IFsKICAgMCAgPT4gJygxOSkgOTk5OTktOTk5OScsCiAgIDEgID0+ICc5OTknLAogICAyICA9PiAnOTk5Ljk5OS45OTktOTknLAogICAzICA9PiAnVGVzdGUgZGUgUmF6w6NvIFNvY2lhbCcsCiAgIDQgID0+ICdPYn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