Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Preg_replace i błąd
Dawid_
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 21.07.2006

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


Witam. Pisałem na innych forach, ale nie wiedzą gdzie tkwi błąd.

  1. <?php
  2. $where=preg_replace( '/(.*)/eiU', "'<a href='.(strpos('$1', 'http://') !== 0) ? 'http://$1' : $1.'>'.(strlen('$1')>20) ? substr('$1',0,10).'(...)'.substr('$1',-10).'</a>'", $where);
  3. ?>


Nie działa to jak należy, bowiem wyskakuje błąd:

Parse error: syntax error, unexpected T_FUNCTION in /home/accounts_m/maks/public_html/r+/conf.php(83) : regexp code on line 1

Fatal error: preg_replace(): Failed evaluating code (...) /home/accounts_m/maks/public_html/r+/conf.php on line 83

Oczekuje na odpowiedź. Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
TomASS
post
Post #2





Grupa: Zarejestrowani
Postów: 1 660
Pomógł: 13
Dołączył: 9.06.2004
Skąd: Wrocław i okolice

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


U mnie kod:
  1. <?php
  2. $where=preg_replace( '/(.*)/eiU', "'<a href='.(strpos('$1', 'http://') !== 0) ? 'http://$1' : $1.'>'.(strlen('$1')>20) ? substr('$1',0,10).'(...)'.substr('$1',-10).'</a>'", $where);
  3. ?>

nie protestuje.

Wpisz:
  1. <?
  2. ?>

i sprawdź czy PCRE (Perl Compatible Regular Expressions) Support jest włączone (Enable).

Dodatkowo sprawdź wersję php, jeśli masz php 3 < 3.0.9, funkcja ta nie będzie działać.

Ten post edytował TomASS 22.07.2006, 12:09:46
Go to the top of the page
+Quote Post
Dawid_
post
Post #3





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 21.07.2006

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


php Version 4.4.2
I mam włączone pcre
Go to the top of the page
+Quote Post
Aure
post
Post #4





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 3.05.2004
Skąd: Warszawa

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


Spróbuj tak:
  1. <?php
  2. $where=preg_replace( '/(.*)/eiU', "'<a href='.(strpos('$1', 'http://') !== 0) ? 'http://$1' : '$1>'.(strlen('$1')>20) ? substr('$1',0,10).'(...)'.substr('$1',-10).'</a>'", $where);
  3. ?>
Go to the top of the page
+Quote Post
Dawid_
post
Post #5





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 21.07.2006

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


Efekt:

Parse error: syntax error, unexpected ';' in /home/accounts_m/maks/public_html/r+/conf.php(97) : regexp code on line 1

Fatal error: preg_replace(): Failed evaluating code: '&lt;a href='.(strpos('php.net.pl/manual/pl/function.substr.php', 'http://') !== 0) ? 'http://php.net.pl/manual/pl/function.substr.php' : 'php.net.pl/manual/pl/function.substr.php&gt;'.(strlen('php.net.pl/manual/pl/function.substr.php')&gt;20) ? substr('php.net.pl/manual/pl/function.substr.php',0,10).'(...)'.substr('php.net.pl/manual/pl/function.substr.php',-10).'&lt;/a&gt;' in /home/accounts_m/maks/public_html/r+/conf.php on line 97
Go to the top of the page
+Quote Post
Aure
post
Post #6





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 3.05.2004
Skąd: Warszawa

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


Teraz powinno działać prawidłowo:

  1. <?php
  2. $where=preg_replace( '/(.*)/eiU', "'<a href=' . ( (strpos('$1', 'http://') !== 0) ? 'http://$1' : '$1>' ) . ( (strlen('$1')>20) ? substr('$1',0,10).'(...)'.substr('$1',-10) : '$1' ) . '</a>'", $where);
  3. ?>

A na przyszłość polecam używania nawiasów do polepszenia czytelności kodu (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
Dawid_
post
Post #7





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 21.07.2006

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


Dziękuje (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

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: 24.12.2025 - 12:51