Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][REG] Dziwny błąd
Forum PHP.pl > Forum > Przedszkole
MWL
Witam, chciałem napisać kod zmieniający przestarzały znacznik font na span. oto kod

  1. <?php
  2. preg_replace('#<font color="(.*?)">(.*?)</font>#si"', '<span style="color:1;">2</span>', $html);
  3. ?>


Po wykonaniu tego kodu nie widzę już niczego. Wiecie może czemu tak się dzieje?? worriedsmiley.gif
Kocurro
Daj:

  1. <?php
  2. $html = preg_replace_all('#<font color="(.*?)">(.*?)</font>#si"', '<span style="color:1;">2</span>', $html);
  3. ?>


pozdrawiam,
Łukasz
Shili
Jak go nie wyświetlasz na ekranie, to nic dziwnego, że nic nie widać.
Zastosuj do niego echo na przykład, a potem usuń ten błąd, który Ci się wyświetli i wszystko powinno grać.
MWL
to nie jest cały kod, nie jestem aż tak głupi i wyświetlam ten tekst. (pozatym to klasa z buforowania)

Kocurro dzięki , ale niestety to jeszcze nie to... twój sposób nie działa
qrees
Cytat(MWL @ 6.08.2008, 16:06:56 ) *
to nie jest cały kod, nie jestem aż tak głupi i wyświetlam ten tekst. (pozatym to klasa z buforowania)

Kocurro dzięki , ale niestety to jeszcze nie to... twój sposób nie działa

Może głupi nie jesteś, ale na to żeby podać jakiś większy fragment kodu to nie wpadłeś. Jak wyświetlasz ten tekst?
MWL
normalnie

ob_start(array('TplController', 'control'));

a ta klasa:

  1. <?php
  2. defined('ACCESS') or die("Direct to this file is forbidden");
  3.  
  4. class TplController {
  5.  
  6.  public function __construct() {
  7. return;
  8.  }
  9.  
  10.  public static function control($buffer) {
  11. // Przetworzenie haed
  12. $head = explode('<head>', $buffer);
  13. $addings_tags = self::addings_tags($head[1]);
  14. $buffer = self::correct_html($head[0]."<head>\n".$addings_tags.$head[1]);
  15. return $buffer;
  16.  }
  17.  
  18.  private function addings_tags($head) {
  19. if(!stripos($head, '<base')) {
  20.  $addings_tags = "<base href=\"".VGL_ADRESS."\" />";
  21. } else {
  22.  $addings_tags = "";
  23. }
  24. if(!stripos($head, '<title>')) {
  25.  $addings_tags .= "\n<title>".VGL_SITE_NAME."</title>";
  26. }
  27. if(!stripos($head, '<meta http-equiv="Content-Language"')) {
  28.  $addings_tags .= "\n<meta http-equiv=\"Content-Language\" content=\"".VGL_LANGUAGE."\" />";
  29. }
  30. if(!stripos($head, '<meta http-equiv="Content-Type"')) {
  31.  $addings_tags .= "\n<meta http-equiv=\"Content-Type\" content=\"".VGL_CODDING."\" />";
  32. }
  33. if(!stripos($head, '<meta name="description"')) {
  34.  $addings_tags .= "\n<meta name=\"description\" content=\"".VGL_SITE_DESC."\" />";
  35. }
  36. if(!stripos($head, '<link rel="alternate" type="application/rss+xml"')) {
  37.  switch(VGL_ST_MOD) {
  38. case '1':
  39.  $rss = 'http://rss.'.VGL_DOMAIN.VGL_CMSDIR;
  40. break;
  41. case '2':
  42.  $rss = VGL_ADRESS.'index.php/rss';
  43. break;
  44. case '3':
  45. default:
  46.  $rss = VGL_ADRESS.'index.php/rss';
  47. break;
  48.  }
  49.  $addings_tags .= "\n<link rel=\"alternate\" type=\"application/rss+xml\" href=\"".$rss."\" />";
  50. }
  51. if(!stripos($head, '<link rel="alternate" type="application/atom+xml"')) {
  52.  switch(VGL_ST_MOD) {
  53. case '1':
  54.  $atom = 'http://atom.'.VGL_DOMAIN.VGL_CMSDIR;
  55. break;
  56. case '2':
  57.  $atom = VGL_ADRESS.'index.php/atom';
  58. break;
  59. case '3':
  60. default:
  61.  $atom = VGL_ADRESS.'index.php/atom';
  62. break;
  63.  }
  64.  $addings_tags .= "\n<link rel=\"alternate\" type=\"application/atom+xml\" href=\"".$atom."\" />";
  65. }
  66. if(!stripos($head, '<link rel="shortcut icon"')) {
  67.  $addings_tags .= "\n<link rel=\"shortcut icon\" href=\"vgl_includes/extras/icon.ico\" />";
  68. }
  69. return $addings_tags;
  70.  }
  71.  
  72.  public function correct_html($html) {
  73. $html = str_replace('<br>', '<br />', $html);
  74. $html = str_replace('<BR>', '<br />', $html);
  75. $html = preg_replace('#<font color="(.*?)">(.*?)</font>#si"', '<span style="color:1;">2</span>', $html);
  76. return $html;
  77.  }
  78.  
  79. }
  80.  
  81. ?>


starczy ci tyle haha.gif
Shili
Cytat
'#<font color="(.*?)">(.*?)</font>#si"'
Mówiłam, że masz błąd. Policz cudzysłowia.

Co do wyświetlania - nie jestem magikiem - ani nie miałeś wyniku przypisanego do zmiennej, ani jej wyświetlonej, warto się było upewnić czy tego nie pominąłeś.

I zmień ponownie na //1 winksmiley.jpg

U mnie po takim poprawieniu działa bez problemu.
MWL
aj te litrówki biggrin.gif
Kocurro
Wybacz wprowadzenie w błąd - zrobiłem kopiuj wklej ... i mi wcięło slashe :/

pozdrawiam,
Łukasz
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.