• 0
Sign in to follow this  
mbleonardo

Substituir Dados De String

Question

Como eu faço para substitui todos os dados de uma string?

Por exemplo, tenho uma variável com o valor

"aaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaa <GGG> aaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaa

<GGG> aaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaa <GGG>"

como eu faço para substituir todos os <GGG> por >PPP< ?

Veleu!

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
Guest André Taiar

$var = "aaaaaaaaaaaaaaa<GGGGGGG>aaaaaaaaaaaaaaa<GGGGGGGG>";

str_replace(">PPPPPP<","<GGGGGGG>" $var);

Share this post


Link to post
Share on other sites
  • 0

o que o andre disse tá quase certo, mas é ao contrário...

primeiro vem o conteúdo do texto que vai ser substituído e depois o que vai substituí-lo, dessa forma:

<?

$texto = "aaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaa <GGG> aaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaa

<GGG> aaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaa <GGG>";

$texto = str_replace("<GGG>",">PPP<",$texto);

echo $texto;

?>

Vê se dá certo...

Share this post


Link to post
Share on other sites
  • 0

Quando você não lembrar de alguma coisa, dá uma olhada nessa página, oh: PHP.net...

É o manual oficial do PHP na net... lá você encontra todas as funções com as suas respectivas explicações e a maioria já foi traduzida pro português... bem facinho... :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this