Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> a/an
dragonsokol
post
Post #1





Grupa: Zarejestrowani
Postów: 31
Pomógł: 2
Dołączył: 23.06.2008

Ostrzeżenie: (0%)
-----


witam,
jest mozliwosc zrobienia w php czegos takiego:
a b
an a
z czego b, a to string przed ktorymi chce dac a/an
Go to the top of the page
+Quote Post
Cysiaczek
post
Post #2





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




LoL biggrin.gif Od początku i pomału ;]


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
dragonsokol
post
Post #3





Grupa: Zarejestrowani
Postów: 31
Pomógł: 2
Dołączył: 23.06.2008

Ostrzeżenie: (0%)
-----


mam apple i banana i przed banana chce wstawic "a" a przed apple "an"
chodzi mi o to jak pobrac 1 literke, czy moze jest od tego jakas funkcja w php
Go to the top of the page
+Quote Post
Cysiaczek
post
Post #4





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Powinno wystarczyć zastąpienie tekstu:
  1. <?php
  2. $str='apple banan apple banan apple';
  3. $str=str_replace('apple', 'an apple', $str);
  4. $str=str_replace('banan', 'a banan', $str);
  5. print $str;
  6. ?>


Aha, mógłbyś nadać jakiś tytuł - normalny ;]


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
Ociu
post
Post #5





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




  1. <?php
  2. $str='apple banan apple banan apple citrona';
  3. $sam=array('a, e, i, o, u');
  4.  
  5. $arrStrings=explode(' ', $str);
  6. foreach($arrStrings as $string) {
  7. if(in_array($string[0], $sam)) print 'an '. $string; else print 'a '. $string;
  8. }
  9. ?>
Go to the top of the page
+Quote Post
Spykaj
post
Post #6





Grupa: Zarejestrowani
Postów: 104
Pomógł: 3
Dołączył: 30.05.2008
Skąd: Białystok

Ostrzeżenie: (0%)
-----


Tak, tylko:

an hour
a user
a university

Tak to jest z językami ;p nawet z angielskim. WYJĄTKI ;p


--------------------
?>
Go to the top of the page
+Quote Post
Ociu
post
Post #7





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




Nie ma problemu. Wystarczy kolejna tablica.
Go to the top of the page
+Quote Post
Babcia@Stefa
post
Post #8





Grupa: Zarejestrowani
Postów: 654
Pomógł: 17
Dołączył: 19.03.2006
Skąd: z kosmosu ;)

Ostrzeżenie: (0%)
-----


Może nie działać tongue.gif

  1. <?php
  2. $str='apple banan apple banan apple citrona';
  3. $sam=array('a, e, i, o, u');
  4. $exceptions = array('user' => 'a', 'hour' => 'an', 'university' => 'a');
  5.  
  6. $arrStrings=explode(' ', $str);
  7. foreach($arrStrings as $string) {
  8.  
  9. if($exceptions[$string] != null)
  10. {
  11. $Print .= $exceptions[$string]. ' ' .$string;
  12. } else {
  13. if(in_array($string[0], $sam)) 
  14. $Print .= 'an '. $string; 
  15. else 
  16. $Print .= 'a '. $string;
  17. }
  18. }
  19. echo $Print;
  20. ?>


--------------------
Środowisko testowe (desktop) - Gedit, lighttpd, sftp, rsync, xfce4-terminal, chromium, firefox4 | System: Gentoo ~x86
O'Neill - serwer WWW @ lighttpd, links, nano, rsyncd, sftpd | System: Debian
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 09:30