Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> wyrazenia regularne i tablica
qbatoja
post
Post #1





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 3.05.2005

Ostrzeżenie: (10%)
X----


czesc mam taki przyklad:
  1. <?php
  2. $arr = array(
  3. 'A' => 'Arbuz',
  4. 'B' => 'Banan');
  5.  
  6. $str = 'A jest smaczny, B jest zgniły';
  7. ?>

jak, za pomoca preg_replace() zrobic, zeby $str reprezentowal napis: "Arbuz jest smaczny, Banan jest zgniły"
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
webdice
post
Post #2


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




  1. <?php
  2. $arr = array ('A' => 'Arbuz', 'B' => 'Banan');
  3.  
  4. $str = 'A jest smaczny, B jest zgniły';
  5.  
  6. foreach ($arr as $key => $value)
  7. {
  8. //print $key . $value;
  9.  
  10. $str = preg_replace ('#' . $key . '#', $value, $str);
  11. }
  12.  
  13. print $str;
  14. ?>


Pisane z palca, ewentualne błędy poprawisz sobie sam.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 12.10.2025 - 14:29