Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak zamienić link na tekst?
Saki
post
Post #1





Grupa: Zarejestrowani
Postów: 240
Pomógł: 2
Dołączył: 5.12.2010
Skąd: Fulda

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


Witam, mam mały problem, muszę zamienić:
z:
Lorem ipsum dolor sit amet, <a href="http://google.com/" target="_blank">[LINK]</a> consectetur adipiscing elit.
na:
"Lorem ipsum dolor sit amet, http://google.com/ consectetur adipiscing elit."

Próbowałem:
  1. $dane[6][$i] = preg_replace("#<a href=\"#", "", $dane[6][$i]);
  2. $dane[6][$i] = preg_replace("#\" target=\"_blank\">[LINK]</a>#", "", $dane[6][$i]);
  3. $dane[6][$i] = preg_replace("#target=\"_blank\">[LINK]</a>#", "", $dane[6][$i]);


Ale usuwa tylko <a href=" a końcówka " target="_blank">[LINK]</a> zostaje.
Czy wiecie jak to naprawić, lub macie lepszy pomysł na zamianę?

Ten post edytował Saki 7.06.2012, 19:38:30
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
k_@_m_i_l
post
Post #2





Grupa: Zarejestrowani
Postów: 349
Pomógł: 72
Dołączył: 22.01.2008
Skąd: Wadowice/Oświęcim

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


  1. $link = '<a id="id2" href="http://google.com/" class="22class" target="_blank">[LINK]</a>';
  2. $preg='#<a(.*)href="(.*?)"(.*)>(.*)<\/a>#is';
  3. $test = preg_replace($preg,'<a$1href="$2"$3>$2</a>',$link);


Ten post edytował k_@_m_i_l 7.06.2012, 20:58:38
Go to the top of the page
+Quote Post
Saki
post
Post #3





Grupa: Zarejestrowani
Postów: 240
Pomógł: 2
Dołączył: 5.12.2010
Skąd: Fulda

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


Cytat(k_@_m_i_l @ 7.06.2012, 21:56:08 ) *
  1. $link = '<a id="id2" href="http://google.com/" class="22class" target="_blank">[LINK]</a>';
  2. $preg='#<a(.*)href="(.*?)"(.*)>(.*)<\/a>#is';
  3. $test = preg_replace($preg,'<a$1href="$2"$3>$2</a>',$link);



Nie działa:
Zwraca: Lorem ipsum dolor sit amet, <a href="http://google.com/" target="_blank">http://google.com/</a> consectetur adipiscing elit.
Zamiast: Lorem ipsum dolor sit amet, http://google.com/ consectetur adipiscing elit.

  1. <?PHP
  2.  
  3. $link = 'Lorem ipsum dolor sit amet, <a href="http://google.com/" target="_blank">[LINK]</a> consectetur adipiscing elit. ';
  4. $preg='#<a(.*)href="(.*?)"(.*)>(.*)<\/a>#is';
  5. $test = preg_replace($preg,'<a$1href="$2"$3>$2</a>',$link);
  6.  
  7. echo $test;
  8. ?>


NIe potrzebuje class i id tylko to: <a href="http://google.com/" target="_blank">[LINK]</a> pobieram to za pomocą curl i nie zostanie nigdy zmienione




Go to the top of the page
+Quote Post

Posty w temacie


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: 8.10.2025 - 14:49