The Little Guy Posted August 31, 2007 Share Posted August 31, 2007 $getvid returns all html from a website. I have tried this: <?php preg_replace("~\<style(.*)\>(.*)\<\/style\>~"," ",$getvid); ?> It doesn't work, all I want to do is remove the style tags, and everything between them. In there place I want to insert a space. Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/ Share on other sites More sharing options...
The Little Guy Posted August 31, 2007 Author Share Posted August 31, 2007 I think I got it using thsi: "/<((?:style)).*>.*<\/\\1>/si", but I guess we will see Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/#findComment-338631 Share on other sites More sharing options...
The Little Guy Posted August 31, 2007 Author Share Posted August 31, 2007 <?php $getvid = preg_replace("/<((?:style)).*>.*<\/style>/si", ' ',$getvid); ?> OK... This doesn't work... any help? for some reason it returns a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/#findComment-338731 Share on other sites More sharing options...
roopurt18 Posted August 31, 2007 Share Posted August 31, 2007 I've found that the preg_* functions seem to crash when the string you're applying the regexp gets large. Try using the regexp on a smaller string first and see if it succeeds. Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/#findComment-338749 Share on other sites More sharing options...
The Little Guy Posted August 31, 2007 Author Share Posted August 31, 2007 I found if I remove the "s" at the end, it doesn't quit, but at the same time it doesn't remove the styles Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/#findComment-338763 Share on other sites More sharing options...
sasa Posted August 31, 2007 Share Posted August 31, 2007 try $getvid = preg_replace('/<\s*style.+?<\s*\/\s*style.*?>/', ' ', $getvid ); Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/#findComment-338951 Share on other sites More sharing options...
The Little Guy Posted September 1, 2007 Author Share Posted September 1, 2007 nope... didn't work Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/#findComment-339066 Share on other sites More sharing options...
Jessica Posted September 1, 2007 Share Posted September 1, 2007 You could use substring and strpos to remove everything between <style> and </style>[code] [/code] Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/#findComment-339067 Share on other sites More sharing options...
dsaba Posted September 1, 2007 Share Posted September 1, 2007 I use this function to grab things inside of markers you can use preg_replace on it its the concept I suppose of what you're asking, play around with it, also your problem might be stripping line breaks before you parse through any source code, <span> is different from <span>\n function get_insideMarkers($left, $right, $raw) { $leftMarker = preg_quote($left, '/'); $rightMarker = preg_quote($right, '/'); $findBulk = preg_match_all('/'.$leftMarker.'(.*?)'.$rightMarker.'/', $raw, $array); $resultArray = $array[1]; return $resultArray; } function stripnl($text) { $text = str_replace("\r\n", "", $text); $text = str_replace("\r", "", $text); $text = str_replace("\n", "", $text); return trim($text); } $raw = stripnl(file_get_contents('url')); $array = get_insideMarkers('<span>', '</span>', $raw); print_r($array); //returns all span tags Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/#findComment-339068 Share on other sites More sharing options...
sasa Posted September 1, 2007 Share Posted September 1, 2007 try $getvid = preg_replace('/<\s*style.+?<\s*\/\s*style.*?>/si', ' ', $getvid ); Quote Link to comment https://forums.phpfreaks.com/topic/67453-solved-remove-style-tags/#findComment-339291 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.