Ir para conteúdo
Fórum Script Brasil
  • 0

Php + json [+Request][+Ajuda]


renandare

Pergunta

Dae galera

To com um problema em fazer o meu php ler o conteudo do banco, e tirar o Chr(13)...

acontece que meu php não tá "entendendo" que no retorno do banco, tem uma quebra de linha..

estou usando duas funções, uma para encodar a string, e outra que seria exatamente para pegar o chr, segue:

Função para tirar o chr(13) (quebra de linha)

function SubAcento($variavel){

$chh=1;
while($chh!=0){

    $chh = strpos($variavel, chr(13));
    
    $tam = strlen($variavel);
    
    if($chh>0){
        $variavel = substr($variavel,0,$chh).substr($variavel,$chh+2,$tam);
    }
    }

    return $variavel;
}
Função para encodar a string.
function SubAcento2($REMOVE_ACENTOS){
   
$REMOVE_ACENTOS = str_replace( "à", "à", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "á", "á", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "â", "â", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ã", "ã", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ä", "ä", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "è", "è", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "é", "é", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ê", "ê", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ë", "ë", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "ì", "ì", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "í", "í", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "î", "î", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ï", "ï", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "ò", "ò", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ó", "ó", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ô", "ô", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "õ", "õ", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ö", "ö", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "ù", "ù", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ú", "ú", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "û", "û", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "ü", "ü", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "À", "À", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Á", "Á", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Â", "Â", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ã", "Ã", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ä", "Ä", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "È", "È", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "É", "É", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ê", "Ê", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ë", "Ë", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "Ì", "Ì", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Í", "Í", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Î", "Î", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ï", "Ï", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "Ò", "Ò", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ó", "Ó", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ô", "Ô", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Õ", "Õ", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ö", "Ö", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "Ù", "Ù", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ú", "Ú", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Û", "Û", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ü", "Ü", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "ç", "ç", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "Ç", "Ç", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "não", "não", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "não", "não", $REMOVE_ACENTOS);

$REMOVE_ACENTOS = str_replace( "´", "´", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "`", "`", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "¨", "¨", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "^", "ˆ", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "~", "˜", $REMOVE_ACENTOS);
$REMOVE_ACENTOS = str_replace( "\"", """, $REMOVE_ACENTOS);

return $REMOVE_ACENTOS;
}

e uso da seguinte forma o resultado da consulta do banco...

$Opiniao = SubAcento2($rs['Opi_Opiniao']);

$Opiniao = SubAcento($Opiniao);

porém não está dando certo, não sei porque...testei a função passando uma string qualquer com <br> dentro dela, e funcionou beleza....

mais na hr de pegar o resultado do banco igual tá acima aí ele não reconhece os <br />, chr(13) e acaba quebrando as linhas...

alguém sabe o que pode ser?

Editado por renandare
Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

Deus! oO

Tipo, vamos ver se eu entendi. Tu tens um texto no banco que está gravado com o char '\n' (new line) é isso? E tu queres retirar esse char? Isso?

E nooooossa! Não tem um jeito melhor pra retirar esses acentos? XD

Link para o comentário
Compartilhar em outros sites

  • 0

Vamos lá então... Já tentastes usar a função nl2br()? Ela é uma função que transforma os \n em <br>... Isso te ajuda? Agora dos acentos, vou procurar...

http://br2.php.net/manual/pt_BR/function.nl2br.php

function retira_acentos( $texto )

{

$array1 = array( "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç"

, "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç" );

$array2 = array( "a", "a", "a", "a", "a", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u", "c"

, "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C" );

return str_replace( $array1, $array2, $texto );

}

Essa eu achei na internet...

Créditos:

http://www.vivaolinux.com.br/scripts/verFo...a%20acentos.php

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...