Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Jak zamienić link na tekst?
Saki
post 7.06.2012, 19:37:32
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


--------------------
Moje serwisy: services.itunix.eu | spytajsie.com

Server: Debian; Desktop: Mac Mini 10.8.1, ArchLinux XFCE
Go to the top of the page
+Quote Post
zalazdi
post 7.06.2012, 19:56:11
Post #2





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.02.2010
Skąd: Elbląg

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


Hmm... A taka opcja odpowiada?

  1. str_replace('<a href="', '', $tekst);
  2. str_replace('" target="_blank">', '', $tekst);


Bez kombinowania na szybko.
Go to the top of the page
+Quote Post
k_@_m_i_l
post 7.06.2012, 20:33:50
Post #3





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

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


  1.  
  2. $link = '<a target="_blank" href="http://google.com/" >abc</a>';
  3. $test = preg_replace('#<a(.*)href="(.*)"(.*)>(.*)<\/a>#is','<a href="$2">$2</a>',$link);


Spróbuj coś takiego.

Ten post edytował k_@_m_i_l 7.06.2012, 20:36:06


--------------------
"PHP to człowiek. MySQL to również człowiek."
Go to the top of the page
+Quote Post
Saki
post 7.06.2012, 20:53:30
Post #4





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:33:50 ) *
  1.  
  2. $link = '<a target="_blank" href="http://google.com/" >abc</a>';
  3. $test = preg_replace('#<a(.*)href="(.*)"(.*)>(.*)<\/a>#is','<a href="$2">$2</a>',$link);


Spróbuj coś takiego.


Nie działa, zostawia " target="_blank"
  1. $test = preg_replace('#<a(.*)href="(.*)"(.*)>(.*)<\/a>#is','$2',$link);


Nie działa, zostawia " target="_blank"

  1. $test = preg_replace('#<a(.*)href="(.*)"(.*)>(.*)<\/a>#is','$2',$link);


Wzór "<a href="http://google.com/" target="_blank">[LINK]</a>" Atrybuty nie mogą zostać zmienione!

Ten post edytował Saki 7.06.2012, 20:54:55


--------------------
Moje serwisy: services.itunix.eu | spytajsie.com

Server: Debian; Desktop: Mac Mini 10.8.1, ArchLinux XFCE
Go to the top of the page
+Quote Post
k_@_m_i_l
post 7.06.2012, 20:56:08
Post #5





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


--------------------
"PHP to człowiek. MySQL to również człowiek."
Go to the top of the page
+Quote Post
Saki
post 7.06.2012, 21:08:17
Post #6





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






--------------------
Moje serwisy: services.itunix.eu | spytajsie.com

Server: Debian; Desktop: Mac Mini 10.8.1, ArchLinux XFCE
Go to the top of the page
+Quote Post
k_@_m_i_l
post 9.06.2012, 09:36:23
Post #7





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

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


Zobacz: http://giermek.info/preg.php
U mnie to jakoś działa.


--------------------
"PHP to człowiek. MySQL to również człowiek."
Go to the top of the page
+Quote Post
krowal
post 9.06.2012, 10:30:04
Post #8





Grupa: Zarejestrowani
Postów: 561
Pomógł: 72
Dołączył: 15.11.2006

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


@k_@_m_i_l Po co dajesz tyle tych atomów skoro potrzebne ci tylko to co znajduje się w href.
  1. preg_replace('/<a .*? href="(.*?)".*?>.*?<\/a>?/is', '<a href="$1">$1</a>', $tekst)


Ten post edytował krowal 9.06.2012, 10:30:25


--------------------
Nawet świnka może wejść na drzewo kiedy jest chwalona :)
Go to the top of the page
+Quote Post
diabel
post 9.06.2012, 18:13:50
Post #9





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 12.12.2011

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


sprawdz czy czasem nie zmieniło Ci < na &lt; i analogicznie >
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 05:37