Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Apr 20, 2006 12:31 pm
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?
Last edited by
s.dot on Thu Apr 20, 2006 4:24 pm, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Apr 20, 2006 12:36 pm
Try taking out the 's' in 'ism' maybe?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Apr 20, 2006 12:38 pm
Same result:
Code: Select all
Array
(
[0] => Array
(
)
[1] => Array
(
)
[2] => Array
(
)
)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Apr 20, 2006 1:46 pm
Code: Select all
preg_match_all('#<\s*style\s*(.*?)>(.*?)<\s*/\s*style.*?>#is', $text, $matches);
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Apr 20, 2006 4:05 pm
This is good.. but doesn't seem to match <style type="text/css"> I've tried playing around with (.+?) with no luck.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Apr 20, 2006 4:07 pm
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',
),
)
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Apr 20, 2006 4:11 pm
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>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Apr 20, 2006 4:15 pm
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);
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Thu Apr 20, 2006 4:24 pm
Fixed.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Thu Apr 20, 2006 4:25 pm
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.