Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Jak wyciąć kawałek adresu strony?
Sylwin
post
Post #1





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 29.10.2006

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


Jak wyciąć kawałek adresu strony i przypisać ja do zmiennych?

Chodzi o to aby np:

http://www.katalog.ngsystem.eu/wpis-11podkat-626.html

$wpis='11'
$podkat='626'

Jak to zrobić ?

Prosze o odpowiedź na podstawie tego linku (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował Sylwin 9.02.2007, 10:40:21
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 12)
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




  1. <?php
  2. $subject = "http://www.katalog.ngsystem.eu/wpis-11podkat-626.html";
  3. $pattern = '/-(d*)/';
  4. $matches = array();
  5. preg_match_all($pattern, $subject, $matches);
  6.  
  7. $wpis = $matches[1][0];
  8. $podkat = $matches[1][1];
  9. echo $wpis.' '.$podkat;
  10. ?>
Go to the top of the page
+Quote Post
Sylwin
post
Post #3





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 29.10.2006

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


Wielki dzięki (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Ale jak teraz zrobić żeby adres:

http://www.katalog.ngsystem.eu/wpis-11podkat-626.html

był zmienną:

$adres='http://www.katalog.ngsystem.eu/dodaj.php';

Czyli zeby kawałek wpis-11podkat-626.html zamieniał sie na dodaj.php ( ma to być uniwersalne)

(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) ?

Ten post edytował Sylwin 9.02.2007, 12:08:10
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




pokombinuj troche z wyrazeniami regularnymi. Akurat to co chcesz jest w miare proste.
http://www.republika.pl/wieluk/strony/wzorce.html
Go to the top of the page
+Quote Post
Sylwin
post
Post #5





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 29.10.2006

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


Coś mi nie idzie...(IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




To pokaz co robisz, a powiemy co robisz źle (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Oczywiscie tym razem musisz uzyc:
http://pl.php.net/manual/pl/function.preg-replace.php
Go to the top of the page
+Quote Post
maryaan
post
Post #7





Grupa: Zarejestrowani
Postów: 380
Pomógł: 2
Dołączył: 5.01.2007

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


nie mozesz uzyc mod rewrite ?
Go to the top of the page
+Quote Post
Sylwin
post
Post #8





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 29.10.2006

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


Nie bardzo bo te adresy bedą wykozystane (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Właściwie tylko tego mi brakuje do działania.]

Wydaje mi sie że ma to być coś takiego

  1. <?php
  2. $pattern = array('/wpis-11podkat-626.html/');
  3. $replace = array('dodaj.php');
  4. $subject = "http://www.katalog.ngsystem.eu/wpis-11podkat-626.html";
  5.  
  6. $adres= preg_replace($pattern, $replace, $subject, 1);
  7. ?>


Ale to ma być uniwersalne...
Jak to przerobić ?

Ten post edytował Sylwin 9.02.2007, 12:40:43
Go to the top of the page
+Quote Post
nospor
post
Post #9





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Cytat
Ale to ma być uniwersalne..
Dlatego wlasnie podalem ci linka do wyrazeni regularnych...

  1. <?php
  2. $pattern = array('/wpis-(.*?).html/');
  3. ?>
Go to the top of the page
+Quote Post
Sylwin
post
Post #10





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 29.10.2006

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


Ok działa bardzo ładnie (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) teraz ostatni etap tworzenia skryptu (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Jak zrobic aby adresy katalogów wczytywały sie kolejno z pliku .txt ?

I zeby

$adres = "http://www.katalog.filozofia.pl/wpis-35podkat-724.html";

zamiast linku tego katalogu wczytywały sie kolejne z plku tekstowego (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
nospor
post
Post #11





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




juz nie przeginaj. teraz twoja kolej:
http://pl.php.net/manual/pl/function.file.php
Go to the top of the page
+Quote Post
Sylwin
post
Post #12





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 29.10.2006

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


No odczyt z pliku:

  1. <?php
  2.  $tablica = file('adresy.txt');
  3.  foreach($tablica as $linijka)
  4.  {
  5. echo $linijka.'<br/>';
  6.  }
  7. ?>



Tylko jak to zrobić zeby nie czytało wszystkich linijek tylki kolejne aż do konca pliku ?

Ten post edytował Sylwin 9.02.2007, 14:10:40
Go to the top of the page
+Quote Post
nospor
post
Post #13





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




nie poto dostales tego linka do manuala, by takie pytania zadawac...
Pierwszy przyklad z komentow:
  1. <?php
  2. $handle = @fopen('yourfile...', "r");
  3. if ($handle) {
  4.  while (!feof($handle)) {
  5.  $lines[] = fgets($handle, 4096);
  6.  }
  7.  fclose($handle);
  8. }
  9. ?>
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.08.2025 - 06:09