Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z zamiana
jarek
post
Post #1





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 29.08.2002

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


Witam,

Mam taki problem pisze obecnie projekt w którym chce wykorzystać templaty cos takiego jak w phpBB2. Tylko nie wiem jak sie zabrac do tego aby skrypt po przeanalizowaniu zawartosci pliku template znalazl wszystkie wyrazenia bedace w formie np. {TYTUL} i zamienil je na odpowiednie elementy tablicy w tym wypadku chcialbym aby zamienialo to na $element['TYTUL'].

Bardzo prosze o pomoc i z góry dziękuje.


pozdrawiam
jarek
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Officerrr
post
Post #2





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 30.08.2002

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


z manuala php
[ciach]

str_replace (mixed search, mixed replace, mixed subject)
This function returns a string or an array with all occurences of search in subject replaced with the given replace value. If you don't need fancy replacing rules, you should always use this function instead of ereg_replace() or preg_replace().

In php 4.0.5 and later, every parameter to str_replace() can be an array.

If subject is an array, then the search and replace is performed with every entry of subject, and the return value is an array as well.

If search and replace are arrays, then str_replace() takes a value from each array and uses them to do search and replace on subject. If replace has fewer values than search, then an empty string is used for the rest of replacement values. If search is an array and replace is a string; then this replacement string is used for every value of search. The converse would not make sense, though.

Przykład 1. str_replace() example
$bodytag = str_replace("%body%", "black", "<body text=%body%>");

[/ciach]
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: 4.10.2025 - 01:52