Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyrazenia regularne <link rel=stylesheet
thelete
post
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 8.12.2006

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


witam
mam problem z wyrazeniami regularnymi (jak zwykle)
w zmiennej $strona mam zrodelko sciagnietej strony
chce z tego zrodla wyciac sciezke do styli znajdujaca sie w tagu
<link rel....>
lub
<style type="text/css">
@import url("sciezka do css")
</style>

nie moge dojsc do ladu ze stworzeniem odpowiedniego wyrazenia regularnego
dla takiego hieroglifu
moze mi ktos w tym pomoc?




doszedlem z wielkimi oporami do czego takiego

  1. <link\b.+?href=(.?)*\b.+rel=['"]stylesheet['"].+?>


i dostaje calego taga <link>

teraz jak z tego wycignac to co za href= (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) ?
i czy to co wyrzezbilem jest w ogole poprawne?

ok doszedlem do czegos takiego

  1. <link\\b.+?href=[\"|\']?([^ \"\\']*)[\"|\']*\\b.+rel=['\"]stylesheet['\"].+?>


wedlug RegexBuddy to niby dziala ale....
tylko na
  1. <link href="/style.css" rel="stylesheet" type="text/css">


a na tym juz nie
  1. <link rel="stylesheet" href="/style.css" type="text/css">



(IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif) (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif) (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif) (IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
thelete
post
Post #2





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 8.12.2006

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


Cytat(bendi @ 8.12.2006, 12:32:10 ) *
No to trzeba niestety 2 regulki napisac, albo jedną z alternatywa:>
Kod
/<link(?:(?:.*?stylesheet.*?href=("|')?(.*?)(?(1)\\1| ))|(?:.*?href=("|')?(.*?)(?(1)\\1| )stylesheet.*?))/

Wynik będzie jako pierwsze lub drugie backreference.



chyba jdnak nie do konca;)

  1. <?php
  2. preg_match("/<link(?:(?:.*?stylesheet.*?href=("|')?(.*?)(?(1)1| ))|(?:.*?href=("|')?(.*?)(?(1)1| )stylesheet.*?))/is", $test, $regs) ;
  3. echo $regs[0];
  4. ?>


w $regs[0] mam

  1. <!-- function generate_address( username ) { var domain = "aardmud.org"; var atsign = "@"; var addr = username + atsign + domain; document.write( "<" + "a" + " " + "href="


to jest czesc zawartosci zmienne $test lecz nie ta czesc ktora mnie interesuje...
kiedy wywale /s z konca zmienna $reg[0] jest pusta
(IMG:http://forum.php.pl/style_emoticons/default/sadsmiley02.gif)

ok doszedlem do tego ze trzeba spacje wytrasnac (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
i wyglada to tak ale...
  1. <?php
  2. preg_match("/<link(?:(?:.*?stylesheet.*?href=("|')?(.*?)(?(1)1|))|(?:.*?href=("|')?(.*?)(?(1)1|)stylesheet.*?)).*>/i", $test, $regs) ;
  3. while(list ($kk,$vv) = each($regs)){
  4.  
  5. echo $kk.' - '.$vv.'<br>';
  6. }
  7. ?>


zwraca mi:
$regs[4] = 'style.css" rel="'

okey

  1. <?php
  2. if (preg_match('/('|")([^('|")]+).css('|")/i', $test, $regs)) {
  3.  echo $regs[0];
  4. } else {
  5.  echo "hjuston łi hef e problem";
  6. }
  7. ?>


dziala

ps. dzieki Insane

Ten post edytował thelete 8.12.2006, 13:11:58
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: 14.10.2025 - 05:55