css - What is the regex for php to get the href value in all stylesheet tags from HTML? -
what general way grab href tags using regex , preg_match_all href value given tag not in order.
example:
<link href="foo.css" rel="stylesheet" type="text/css"/> <link type="text/css" href="bar.css" rel="stylesheet"/> <link rel="stylesheet" type="text/css" href="bar1.css"/> <link type="text/css" href="bar2.css" rel="stylesheet"></link> <link href="path/foo.css" rel="stylesheet" type="text/css"/>
should result in :
array( 'foo.css', 'bar.css', 'bar1.css', 'bar2.css', 'path/foo.css', )
the regex expression looking this, require bit further refinement:
<link\s+(?:[^>]*?\s+)?href="([^"]*)"
testing against
<link href="foo.css" rel="stylesheet" type="text/css"/>
the returned value is
<link href="foo.css"
here's place test out expressions: http://regexpal.com/
Comments
Post a Comment