Page 1 of 1
Trying to grab stylesheets [SOLVED]
Posted: Thu Apr 20, 2006 12:31 pm
by s.dot
I'm trying to run a mass script to modify my users stylesheets.
So I'm trying to snatch all stylesheets that they are using on their page.. I'm trying the following regex
Code: Select all
preg_match_all("/<style (.+?)>(.+?)<\/style>/ism",$data,$matches);
This is always coming up empty. Can someone give me a pointer?
Posted: Thu Apr 20, 2006 12:36 pm
by pickle
Try taking out the 's' in 'ism' maybe?
Posted: Thu Apr 20, 2006 12:38 pm
by s.dot
Same result:
Code: Select all
Array
(
[0] => Array
(
)
[1] => Array
(
)
[2] => Array
(
)
)
Posted: Thu Apr 20, 2006 1:46 pm
by feyd
Code: Select all
preg_match_all('#<\s*style\s*(.*?)>(.*?)<\s*/\s*style.*?>#is', $text, $matches);
Posted: Thu Apr 20, 2006 4:05 pm
by s.dot
This is good.. but doesn't seem to match <style type="text/css"> I've tried playing around with (.+?) with no luck.
Posted: Thu Apr 20, 2006 4:07 pm
by feyd
unless I wrote it completely wrong, it should match that tag.
Edit, yep it matches just fine.
Code: Select all
[feyd@home]>php -r "$text = '<style type="text/css">blahlbha</style>'; preg_match_all('#<\s*style\s*(.*?)>(.*?)<\s*/\s*style.*?>#is', $text, $matches); var_export($matches);"
array (
0 =>
array (
0 => '<style type=text/css>blahlbha</style>',
),
1 =>
array (
0 => 'type=text/css',
),
2 =>
array (
0 => 'blahlbha',
),
)
Posted: Thu Apr 20, 2006 4:11 pm
by s.dot
When I run it on one page that has both <style>something</style> and <style type="text/css">something</style> it grabs this
Code: Select all
<style>
a .text
{
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
</style>
Posted: Thu Apr 20, 2006 4:15 pm
by s.dot
There is this in the source
Code: Select all
<style type="text/css">
.mygen { Created using MyGen 2.5 - www.mygen.co.uk }
.mygen { Background Properties }
table, tr, td { background-color:transparent; border:none; border-width:0;}
body {
background-image:url('http://i2.tinypic.com/v8q5j6.jpg');
background-attachment:fixed;
background-repeat:repeat;
border-color:FFDDFF;
border-width:14px ;
border-style: solid;
scrollbar-face-color:FFDDFF;
scrollbar-highlight-color:FFDDFF;
scrollbar-3dlight-color:FFDDFF;
scrollbar-shadow-color:FFDDFF;
scrollbar-darkshadow-color:FFDDFF;
scrollbar-arrow-color:FFDDFF;
scrollbar-track-color:FFDDFF;
}
.mygen { Table Properties }
table table { border: 0px }
table table table table{border:0px}
table table table {
border-style:solid;
border-width:3px;
border-color:FFDDFF;
}
.mygen { Text Properties }
table, tr, td, li, p, div { color:FFDDFF; font-weight:bold; }
.btext { color:FFDDFF; font-weight:bold; }
.blacktext10 { color:FFDDFF; font-weight:bold; }
.blacktext12 { color:FFDDFF; font-weight:bold; }
.lightbluetext8 { color:FFDDFF; font-weight:bold; }
.orangetext15 { color:FFDDFF; font-weight:bold; }
.redtext { color:FFDDFF; font-weight:bold; }
.redbtext { color:FFDDFF; font-weight:bold; }
.text { color:FFDDFF; font-weight:bold; }
.whitetext12 { color:FFDDFF; font-weight:bold; }
a:active, a:visited, a:link { color:FFDDFF; font-weight:bold; }
a:hover { color:FFDDFF; }
a.navbar:active, a.navbar:visited, a.navbar:link { color:FFDDFF; font-weight:bold; }
a.navbar:hover { color:FFDDFF; }
a.redlink:active, a.redlink:visited, a.redlink:link { color:FFDDFF; font-weight:bold; }
a.redlink:hover { color:FFDDFF; }
.nametext { color:FFDDFF; font-weight:bold; }
</style>
I am fetching it using
Code: Select all
$profile = file_get_contents($thispage);
preg_match_all('#<\s*style\s*.*?>.*?<\s*/\s*style.*?>#is', $profile, $matches);
foreach($matches[0] AS $fullmatch){
echo htmlentities($fullmatch,ENT_QUOTES);
}
Posted: Thu Apr 20, 2006 4:24 pm
by s.dot
Fixed.
Posted: Thu Apr 20, 2006 4:25 pm
by n00b Saibot
Try this regex
Code: Select all
#<\s*style[^>]*>.*?<\s*/\s*style\s*?>#is
BTW, I don't think you need to match for spaces inside tags.