|
|
PHP (angielski akronim rekurencyjny, którego rozwinięcie to PHP Hypertext Preprocessor), pierwotnie nazwany Personal
Home Page - skryptowy język programowania, służący przede wszystkim do tworzenia dynamicznych stron WWW i wykonywany w
tym przypadku po stronie serwera, z możliwością zagnieżdżania w HTML (bądź XHTML). PHP jest podobny w założeniach do
dużo starszego mechanizmu SSI (Server Side Includes), jednak jest w stosunku do SSI nieporównanie bardziej rozbudowany.
Udostępniany jest na zasadach licencji open-source. Jego składnia bazuje na językach C, Java i Perl.
SQL (ang. Structured Query Language) to strukturalny język zapytań używany do tworzenia, modyfikowania baz danych oraz
do umieszczania i pobierania danych z baz danych.
Język SQL jest językiem deklaratywnym. Decyzję o sposobie przechowywania i pobrania danych pozostawia się systemowi
zarządzania bazą danych DBMS.
Jest to język programowania opracowany w latach siedemdziesiątych w firmie IBM. Stał się on standardem w komunikacji z
serwerami relacyjnych baz danych. Wiele współczesnych systemów relacyjnych baz danych używa do komunikacji z
użytkownikiem SQL, dlatego mówi się, że korzystanie z relacyjnych baz danych, to korzystanie z SQL-a.
Apache jest otwartym serwerem HTTP dostępnym dla wielu systemów operacyjnych (m.in. UNIX, GNU/Linux, BSD,
Microsoft Windows). Po angielsku słowo Apache wymawia się epaczi, co brzmi tak samo jak a patchy (server), co było
określeniem tego serwera we wczesnym stadium jego rozwoju w 1995 roku, kiedy był on głównie zbiorem poprawek (patch)
nałożonych na serwer HTTP o nazwie NCSA.
Apache jest najszerzej stosowanym serwerem HTTP w Internecie. W maju 2003 jego udział wśród serwerów wynosił 62%. W
połączeniu z interpreterem języka skryptowego PHP i bazą danych MySQL, Apache stanowi jedno z najczęściej spotykanych
środowisk w firmach oferujących miejsce na serwerach sieciowych.
|
ereg_replace
(PHP 3, PHP 4, PHP 5) ereg_replace -- Replace regular
expression
Descriptionstring ereg_replace ( string pattern, string
replacement, string string )
This function scans string for
matches to pattern, then replaces
the matched text with replacement.
The modified string is returned. (Which may mean that the
original string is returned if there are no matches to be
replaced.)
If pattern contains
parenthesized substrings, replacement may contain substrings of the
form \\digit, which will be replaced by the
text matching the digit'th parenthesized substring; \\0 will produce the entire contents of string.
Up to nine substrings may be used. Parentheses may be nested,
in which case they are counted by the opening parenthesis.
If no matches are found in string, then string will be returned unchanged.
For example, the following code snippet prints "This was a
test" three times:
Przykład 1. ereg_replace() example
<?php
$string = "This is a test";
echo str_replace(" is", " was", $string);
echo ereg_replace("( )is", "\\1was", $string);
echo ereg_replace("(( )is)", "\\2was", $string);
?> |
|
One thing to take note of is that if you use an integer
value as the replacement
parameter, you may not get the results you expect. This is
because ereg_replace() will interpret
the number as the ordinal value of a character, and apply that.
For instance:
Przykład 2. ereg_replace() example
<?php /* This will not work as expected. */
$num = 4; $string = "This string has four words.";
$string = ereg_replace('four', $num, $string);
echo $string; /* Output: 'This string has words.' */
/* This will work. */ $num = '4'; $string = "This string has four words.";
$string = ereg_replace('four', $num, $string);
echo $string; /* Output: 'This string has 4 words.' */
?> |
|
Przykład 3. Replace URLs with links
<?php
$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\">\\0</a>", $text);
?> |
|
Podpowiedź: preg_replace(), which uses a
Perl-compatible regular expression syntax, is often a
faster alternative to ereg_replace().
See also ereg(), eregi(),
eregi_replace(), str_replace(), and preg_match().
|