Hi, simple problem again: <?php $data=file_get_contents("http://www.domain.com/"); preg_match('/<style(.*)?>(.*) ? <\/style>/', $match ); print ($match); ?> PHP: I try to print out the content inside <style type="text/css">xxx</style> Anyone know what's wrong with this code`? Thanks,
Hey, thanks alot to both of you.. now it outputs: Array ( ) //this is what i try to do: <?php $data = file_get_contents("http://www.twitter.com/username/"); preg_match('/<style[^>]+>(.*?)<\/style>/', $data, $match); print_r($match); ?> PHP: Thanks
Hi, try this preg_match('#\<style(.*)?\stype=[\'\"]text\/css[\'\"](.*)?\>(.*)?\<\/style\>#i',$data,$match); PHP: Regards
You're right, that didn't work. This is how I usually scrape stuff: $html = file_get_contents("http://www.twitter.com/username/"); $dom = new DOMDocument(); @$dom->loadHTML($html); $styles = $dom -> getElementsByTagName('style'); foreach ($styles as $style) { if ($style->getAttribute('type') == "text/css") { $css = $style -> firstChild -> data; echo $css; } } PHP:
#<style[^>]+>(.*?)</style># this works fine if you add ISM to the last # char! then it checks multiple lines! #<style[^>]+>(.*?)</style>#ism