Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]zamiana tekstu (preg_replace)
Przemo_
post 25.04.2008, 16:25:34
Post #1





Grupa: Zarejestrowani
Postów: 62
Pomógł: 1
Dołączył: 12.06.2007

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


Witam. Od kilku godzin chcę rozwiązać naprawdę prostą rzecz.

A mianowicie, chcę by mój link został przerobiony.

Mam np. Taki link

  1. <?php
  2. <a href=&#092;"http://rs291.rapidshare.com/files/96800260/dl/Thank_You.rar\" target=\"_blank\">http://rs291.rapidshare.com/files/96800260/dl/Thank_You.rar</a>
  3. ?>



i chciałbym, by po edycji link przyjął taką postać

  1. <?php
  2. <a href=&#092;"http://moja_strona.pl/rs291/96800260/Thank_You.rar\" target=\"_blank\">http://moja_strona.pl/rs291/96800260/Thank_You.rar</a>
  3. ?>


Oto mój kod

  1. <?php
  2. $string = 'http://rs291.rapidshare.com/files/96800260/dl/Thank_You.rar<br /><br /><br />';
  3.  
  4. $page = ereg_replace(".http://", "", $string);
  5. $page = ereg_replace("..rapidshare.com/files", "", $string);
  6. ?>

To akurat wycina ale nie mam pojęcia jak dalej zrobić.
Próbowałem także z preg_replace i także mi nie wychodziło.

Proszę o pomoc. Dzięki smile.gif

Ten post edytował Przemo_ 25.04.2008, 16:40:53
Go to the top of the page
+Quote Post
Piniek
post 25.04.2008, 16:38:15
Post #2





Grupa: Przyjaciele php.pl
Postów: 463
Pomógł: 49
Dołączył: 27.12.2007
Skąd: Warszawa

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


Proszę o dodanie odpowiednich tagów do tematu.
Pozdrawiam


--------------------
Go to the top of the page
+Quote Post
Crozin
post 25.04.2008, 16:57:10
Post #3





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

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


  1. <?php
  2. $string = 'http://rs291.rapidshare.com/files/96800260/dl/Thank_You.rar';
  3. preg_match('#http://([^.]+).*?files/([0-9]+)/[a-z]+/([^"]+)#Ui', $string, $matches);
  4.  
  5. echo '<pre>' . print_r($matches, 1) . '</pre>';
  6. ?>
Pisane z palca.
Mając już odpowiednie dane wystarczy "wpleść" je we własny adres.
Go to the top of the page
+Quote Post
nevt
post 25.04.2008, 17:02:23
Post #4





Grupa: Przyjaciele php.pl
Postów: 1 595
Pomógł: 282
Dołączył: 24.09.2007
Skąd: Reda, Pomorskie.

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


  1. <?php
  2. $old = '<a href="http://rs291.rapidshare.com/files/96800260/dl/Thank_You.rar" '.
  3.  'target="_blank">http://rs291.rapidshare.com/files/96800260/dl/Thank_You.rar</a>';
  4.  
  5. $new = preg_replace('/http://(.*?).rapidshare.com/files/(.*?)("|<)/', 
  6. 'http://moja_strona.pl/${1}/${2}${3}', $old);
  7.  
  8. echo "$old<br />$new";
  9. ?>


--------------------

-
Oh no, my young coder. You will find that it is you who are mistaken, about a great many things... -
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: 12.06.2025 - 10:37