Jump to content


Photo

Php + Json [+ajuda]


  • Faça o login para participar
3 replies to this topic

#1 renandare

renandare

    Novato no fórum

  • Usuários
  • 2 posts
  • Sexo:Não informado

Posted 09/12/2008, 20:18

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( "ô", "&ocirc", $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);

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 pq...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...


alguem sabe oq pode ser?

Edição feita por: renandare, 09/12/2008, 20:18.


#2 fly2k

fly2k

    Super Veterano

  • Usuários
  • 2262 posts
  • Sexo:Não informado

Posted 10/12/2008, 06:01

Como assim acaba quebrando as linhas?

Quebrar as linhas é a função do <br /> e do \n.

Você não quer que ele faça isso?
Quer aprender PHP? -> www.manjaphp.com.br
Tutoriais, código colaborativo (pastebin), curso de PHP, artigos e etc.

#3 renandare

renandare

    Novato no fórum

  • Usuários
  • 2 posts
  • Sexo:Não informado

Posted 10/12/2008, 15:28

Como assim acaba quebrando as linhas?

Quebrar as linhas é a função do <br /> e do \n.

Você não quer que ele faça isso?

exatamente...
não quero que quebre linha...
preciso gerar uma string...

vamos dizer que o usuario digite
oi
meu
nome
é
fulano.

ele não pode trazer assim pra mim, preciso que seja
oi meu nome é fulano.
sacou?

#4 fly2k

fly2k

    Super Veterano

  • Usuários
  • 2262 posts
  • Sexo:Não informado

Posted 10/12/2008, 19:33

Tenta :

str_replace(array("\n", "\r", '<br />'), array('', '', ''), $string);
Quer aprender PHP? -> www.manjaphp.com.br
Tutoriais, código colaborativo (pastebin), curso de PHP, artigos e etc.




0 user(s) are reading this topic

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq