Post
#1
|
|
|
Grupa: Zarejestrowani Postów: 260 Pomógł: 0 Dołączył: 18.07.2003 Skąd: Tarnów Ostrzeżenie: (0%)
|
jako ze jestem zielony w wyrazeniach regularnych a nie udalo mi sie znalezc przyjaznego kursu prosze o pomoc z poprawa funkcji podmieniajacej znaczniki (cos w stylu bbCode) w stringu. zrobilem to na str_replace (z reszta i tak beznadziejnie ale nie chcalo mi sie poprawiac :wink:) i chcialbym to zastapic uzyciem preg_match. z gory tnx za pomoc (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
[php:1:52d8ccad3a]<?php function bbCode ($text) { // bbCode() $text = nl2br($text); // usuwa puste znaczniki $text = str_replace("[ b ][/ b ]", "", $text); // musialem dodac space zeby forum nie parsowalo $text = str_replace("[ i ][/ i ]", "", $text); $text = str_replace("[ u ][/ u ]", "", $text); $text = str_replace("[img][/img]", "", $text); $text = str_replace("", "", $text); // zamienia znaczniki na html $text = str_replace("[ b ]", "<b>", $text); $text = str_replace("[/ b ]", "</b>", $text); $text = str_replace("[ i ]", "<i>", $text); $text = str_replace("[/ i ]", "</i>", $text); $text = str_replace("[ u ]", "<u>", $text); $text = str_replace("[/ u ]", "</u>", $text); $text = str_replace("[img]", '<img src="', $text); $text = str_replace("[/img]", '" alt="" align="left">', $text); $text = str_replace("[url=", '<a href="', $text); $text = str_replace("[/url]", "</a>", $text); // zamiana kolorow $text = str_replace("[color=", '<span style="color: ', $text); $text = str_replace("[/color]", "</span>", $text); // zmiana wielkosci textu $text = str_replace("[size=", '<span style="font-size: ', $text); $text = str_replace("[/size]", "</span>", $text); $text = str_replace("]", '">', $text); /* to robi najwiecej zamieszania, np. gdy w stringu (konkretnie tresci newsa) wystepuja nawiasy kwadratowe nie zwiazane ze znacznikami */ return $text; } ?>[/php:1:52d8ccad3a] update: chyba preg_match (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) mozliwe ze preg_replace albo jeszcze jakas inna funkcja (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) |
|
|
|
borec str_replace => preg_match 20.02.2004, 21:04:11
borec po glebszym przemyslunku: chyba popatrze w kod php... 20.02.2004, 21:13:59
BzikOS Skoro udało Ci się to zrobić przy pomocy str_repla... 20.02.2004, 22:15:53
borec CytatRegexpy Ci się przydadzą wtedy, gdy będziesz ... 20.02.2004, 22:36:30
BzikOS Aż przysiadłem nad tym i zacząłem skrobać Oto co ... 20.02.2004, 23:37:21
borec 8O aha, dzieki 21.02.2004, 09:39:27 ![]() ![]() |
|
Aktualny czas: 22.12.2025 - 15:20 |