Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Usuwanie z tekstu
Forum PHP.pl > Forum > Przedszkole
robak142
Witam,
Na mojej witrynie mam zainstalowane coś na kształt pluginu, dzięki któremu w tekście mogę prezentować zdjęcia z galerii, wpisując w tekście {galery XXX left} lub {galery XXX right}.
Gdzie XXX to numer id zdjęcia z tabeli bazy danych galerii, left lub right odpowiada za opływanie tekstu.
Sekwencje czasami pojawiają się pojedynczo, a czasami w grupach.
Przykład:
--------------------------
{galery XXX left}Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

{galery XXX right}{galery XXX right}{galery XXX right}{galery XXX right}It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
{galery XXX left}{galery XXX left}
------------------------
Dla co niektórych odsłon chciałbym wycinać w/w w php. Oczekiwanym efektem oczywiście jest:

-----------------------
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
-----------------------
Proszę o pomoc i z góry dziękuję.
Turson
  1. $string = preg_replace("/{(.*)}/i", "", $string);
robak142
Cytat(Turson @ 28.01.2014, 12:12:59 ) *
  1. $string = preg_replace("/{(.*)}/i", "", $string);

Dziękuję,
Ten skrypt wytnie wszystko co jest pomiędzy nawiasami klamrowymi wraz z nimi. Mam jeszcze inne pluginy działające w podobny sposób. Chciałbym, aby wycinał tylko ten konkretny {galery xxx left} lub {galery xxx right}
Turson
  1. $string = preg_replace("/{galery \w right}/", "", $string);
  2. $string = preg_replace("/{galery \w left}/", "", $string);
robak142
Nie chcę nadużywać Twojego czasu i wiedzy, ale ten kod w ogóle na to nie działa. Jakieś inne pomysły?
Pozdrawiam
Cytat(Turson @ 28.01.2014, 15:02:33 ) *
  1. $string = preg_replace("/{galery \w right}/", "", $string);
  2. $string = preg_replace("/{galery \w left}/", "", $string);

Turson
Działa

  1. $string = "{galery 1 left}Lorem Ipsum is simply dummy text {galery cos tam} of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
  2.  
  3. {galery 2 right}{galery 1 right}{galery 1 right}{galery 1 right}It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  4. {galery 1 left}{galery 1 left}";
  5. $string = preg_replace("/{galery \w right}/", "", $string);
  6. $string = preg_replace("/{galery \w left}/", "", $string);
  7. echo $string;
-robak142-
Cytat(Turson @ 28.01.2014, 15:33:57 ) *
Działa

  1. $string = "{galery 1 left}Lorem Ipsum is simply dummy text {galery cos tam} of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
  2.  
  3. {galery 2 right}{galery 1 right}{galery 1 right}{galery 1 right}It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  4. {galery 1 left}{galery 1 left}";
  5. $string = preg_replace("/{galery \w right}/", "", $string);
  6. $string = preg_replace("/{galery \w left}/", "", $string);
  7. echo $string;


Działa tylko w przypadku jeżeli wartość liczbowa jest w przedziale 0<=XXX<=9. Czyli w poniższym przykładzie nie zadziała. A to przykład z życia wzięty
  1. $string = "{galery 1532 left}Lorem Ipsum is simply dummy text {galery cos tam} of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.{galery 2322 right}{galery 1421 right}";
  2. $string = preg_replace("/{galery \w right}/", "", $string);
  3. $string = preg_replace("/{galery \w left}/", "", $string);
  4. echo $string;

Wciąż nie ustaję w nadziei, że mi pomożesz. Pozdrawiam.
Turson
  1. $string = "{galery 1 left}{galery 1532 left}Lorem Ipsum is simply dummy text {galery cos tam} of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.{galery 2322 right}{galery 1421 right}";
  2. $string = preg_replace("/{galery \d* right}/", "", $string);
  3. $string = preg_replace("/{galery \d* left}/", "", $string);
  4. echo $string;
-robak142-
Działa perfekcyjnie. Dziękuję za pomoc i poświęcony czas.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.