eevan79 Posted August 21, 2010 Share Posted August 21, 2010 Here is my code for spoiler tag: $search: '/\[spoiler\][\r\n]*(.+?)\[\/spoiler\][\r\n]*/si', $replace: '<div class="spoiler"><input type="button" onclick="showSpoiler(this);" value="Show/Hide" /><div class="inner" style="display:none;">$1</div></div>'); Now I want to reverse back html code to [ spoiler ] text [ / spoiler ] Here is my code, but its not working $search '/<div class="spoiler"><input type="button" onclick="showSpoiler(this);" value="Show/Hide" /><div class="inner" style="display:none;">(.+?)<\/div><\/div>/is' $replace ' [spoiler]\\1[/spoiler] ' Can somebody help me to get this HTML to spoiler bbcode? Quote Link to comment https://forums.phpfreaks.com/topic/211350-regex-for-spoiler-tag/ Share on other sites More sharing options...
eevan79 Posted August 21, 2010 Author Share Posted August 21, 2010 So far I have tried following code: $search = array( '/<div class="spoiler"><input type="button" onclick="showSpoiler(this);" value="Show\/Hide" \/><div class="inner" style="display:none;">(.+?)<\/div><\/div>/is' ); $replace = array( ' [spoiler]\\1[/spoiler] ' ); But it does not working. What I am doing wrong...? Quote Link to comment https://forums.phpfreaks.com/topic/211350-regex-for-spoiler-tag/#findComment-1102021 Share on other sites More sharing options...
sasa Posted August 21, 2010 Share Posted August 21, 2010 $patern = '/<div class="spoiler"><input type="button" onclick="showSpoiler\(this\);" value="Show\/Hide" \/><div class="inner" style="display:none;">(.+?)<\/div><\/div>/is'; Quote Link to comment https://forums.phpfreaks.com/topic/211350-regex-for-spoiler-tag/#findComment-1102145 Share on other sites More sharing options...
eevan79 Posted August 21, 2010 Author Share Posted August 21, 2010 Thanks. Its working. Quote Link to comment https://forums.phpfreaks.com/topic/211350-regex-for-spoiler-tag/#findComment-1102187 Share on other sites More sharing options...
GoneNowBye Posted August 22, 2010 Share Posted August 22, 2010 Quite often you need to consider what is a litteral backslash for example preg_whatever("/\n/") puts a new line character in there preg_whatever("/\\n/") puts a backslash and an n in and is thus a new line character to the REGEX Engine Quote Link to comment https://forums.phpfreaks.com/topic/211350-regex-for-spoiler-tag/#findComment-1102393 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.