Solarpitch Posted March 30, 2011 Share Posted March 30, 2011 Hi Guys, I have the following $pattern = '<tr class="newsitem">'; when I echo this out it produces <tr class="newsitem"> </tr> Why is it automatically closing the tag? I dont want this becuase i'm using preg_replace and the tag is closed elsewhere already on the page. Link to comment https://forums.phpfreaks.com/topic/232226-tag-automatically-closing/ Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 I doubt that is actually happening, it's probably somethign much simpler. can you post the full code. Link to comment https://forums.phpfreaks.com/topic/232226-tag-automatically-closing/#findComment-1194655 Share on other sites More sharing options...
Solarpitch Posted March 30, 2011 Author Share Posted March 30, 2011 Actually, I think its to do with the preg_replace on my last post. $code = preg_replace('#<!--STRIP-->(.*)<!--STRIP-->#s', '', $post); Whats happening with this is, It takes the last <!--STRIP--> on the page, and removes everything from that to the last <!--ENDSTRIP--> so if I have <!--STRIP--> // Will strip from here html code... <!--ENDSTRIP--> html code... <div>This is outside, but will get removed when it shouldnt</div> <!--STRIP--> html code... some html code <!--ENDSTRIP--> <!--STRIP--> html code... for this example <!--ENDSTRIP--> // To here Is there a way round this? Link to comment https://forums.phpfreaks.com/topic/232226-tag-automatically-closing/#findComment-1194678 Share on other sites More sharing options...
betterphp Posted March 30, 2011 Share Posted March 30, 2011 you can make it ungreedy, which will make it match the shortest possible string. $code = preg_replace('#<!--STRIP-->(.*)<!--STRIP-->#Us', '', $post); Link to comment https://forums.phpfreaks.com/topic/232226-tag-automatically-closing/#findComment-1194685 Share on other sites More sharing options...
Solarpitch Posted March 30, 2011 Author Share Posted March 30, 2011 Thanks again. That done the job. Link to comment https://forums.phpfreaks.com/topic/232226-tag-automatically-closing/#findComment-1194687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.