View previous topic :: View next topic |
Author |
Message |
vedran
![](images/avatars/18547581264195ec291b6f2.gif)
Joined: 08 Sep 2003 Posts: 458
|
Posted: 22.06.2005 13:53 Post subject: php: replace funkcija unutar petlje |
|
|
Trebao bih primjer funkcije u php-u koja bi uzela neku recenicu(naslov iz baze) i zamijenila sva przna mjesta unutar tog stringa sa - (crticom).
Naime koristim mod_rewrite i svi urlovi se otvaraju prema naslovu novosti, pa bi se ta funkcija trebala pobrinuti da u url-u nema praznih mjesta..
Pa ako netko može nabrzinu napisati primjer ili ima gotovi bio bih jako zahvalan.
![Smile](images/smiles/icon_smile.gif) |
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
ante
![](images/avatars/19279410184288e339b98e1.gif)
Joined: 09 Oct 2003 Posts: 255 Location: st
|
Posted: 22.06.2005 14:05 Post subject: |
|
|
Jel str_replace funkcija može?
Code: | str_replace(string to search for, replacement string, string to be searched trough); |
Pogledaj u php manualu detalje i primjere. http://hr.php.net |
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
unique
Joined: 29 Mar 2004 Posts: 655
|
Posted: 22.06.2005 14:06 Post subject: |
|
|
s pretpostavkom da vec imas tu recenicu iz baze...
Code: | $recenica="Dali Vedran zeli ovo?";
for ($k=0;$k<strlen($recenica);$k++) if($recenica[$k]==' ') $recenica[$k]='-';
echo $recenica; |
ili ko funkcija :]
Code: | $recenica="Dali Vedran zeli ovo?";
function crtice($recenica){
for ($k=0;$k<strlen($recenica);$k++) if($recenica[$k]==' ') $recenica[$k]='-';
retrun $recenica
}
echo crtice($recenica); |
|
_________________ Activate interlock! Dynotherms connected! Infracells up! Mega thrusters are go! LET'S GO VOLTRON FORCE! |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
vedran
![](images/avatars/18547581264195ec291b6f2.gif)
Joined: 08 Sep 2003 Posts: 458
|
Posted: 22.06.2005 14:10 Post subject: |
|
|
unique wrote: | s pretpostavkom da vec imas tu recenicu iz baze...
Code: | $recenica="Dali Vedran zeli ovo?";
for ($k=0;$k<strlen($recenica);$k++) if($recenica[$k]==' ') $recenica[$k]='-';
echo $recenica; |
ili ko funkcija :]
Code: | $recenica="Dali Vedran zeli ovo?";
function crtice($recenica){
for ($k=0;$k<strlen($recenica);$k++) if($recenica[$k]==' ') $recenica[$k]='-';
retrun $recenica
}
echo crtice($recenica); |
|
Da-Vedran-želi-baš-to
Puno hvala na brzom i točnom odgovoru. |
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
che.UP mi3.crew
![](images/avatars/85218352741ca315781887.gif)
Joined: 07 Sep 2003 Posts: 2320 Location: zagreb
|
Posted: 22.06.2005 14:26 Post subject: |
|
|
zasto bi bilo jednostavno kad moze bit komplicirano :)
ante ti je dobro rekao, treba ti str_replace
Code: | str_replace(' ', '-', $recenica); |
|
_________________ UP | TypeTester | Accommodations App
Meni u Firefox-u ne radi AJAX |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
nel`chee
![](images/avatars/3994668404ef986987ff64.gif)
Joined: 08 Jul 2004 Posts: 2087 Location: Rijeka
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
che.UP mi3.crew
![](images/avatars/85218352741ca315781887.gif)
Joined: 07 Sep 2003 Posts: 2320 Location: zagreb
|
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|