kla0005 Posted January 27, 2010 Share Posted January 27, 2010 Hi Guys, Well, i have tryed to make a Turtorial system with bbCode that inserts a 'Show this code box' .. And the code that has to be showed i write inside [ code] & [ /code] - But when im taking the code out i have to make <br /> with the nl12br function, but when i do that, the code in the box will get <br /> to! and then there will be alot of <br /> in the middle of my code in the box'es.. I have tryed to remove the <br /> beetwen the [ code] with: function replace_br($input){ $text = str_replace("<br />","", $input); $ret = '<div class="code"><pre class="brush: php;">'.$text.'</pre></div>'; return $ret; } $turtorial = stripslashes(nl2br($foresp['turtorial'])); $turtorial = preg_replace("/\\[ code\\](.+?)\[\/code\]/is",replace_br('\1'), $turtorial); echo $turtorial; But the function dosnet get the \1 information? .. What could i have done wrong... Someone who can help me? Thanks.. - Jonatan (sorry for the spaces beetwen [ and c in [ code .. But the forum dosent like im writing them so xD) Quote Link to comment https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/ Share on other sites More sharing options...
Catfish Posted January 27, 2010 Share Posted January 27, 2010 Not sure on this one but a quick read of manual said you can use $1 as preferred to \1 since PHP 4.0.4. Maybe \1 is being deprecated? Try: $turtorial = preg_replace("/\\[ code\\](.+?)\[\/code\]/is",replace_br($1), $turtorial); Quote Link to comment https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002505 Share on other sites More sharing options...
kla0005 Posted January 27, 2010 Author Share Posted January 27, 2010 Not sure on this one but a quick read of manual said you can use $1 as preferred to \1 since PHP 4.0.4. Maybe \1 is being deprecated? Try: $turtorial = preg_replace("/\\[ code\\](.+?)\[\/code\]/is",replace_br($1), $turtorial); Nah, that didn't work .. It just returned a string with "$1" .. /; BUT! - It still returns the string, i just cant see it? Like its hidden but when i return it the php writes it.. I cant chance it.. Is there anykind of function that converts \1 / $1 to string? .. This is so weird! Quote Link to comment https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002514 Share on other sites More sharing options...
Daniel0 Posted January 27, 2010 Share Posted January 27, 2010 Use preg_replace_callback or use the /e modifier. Quote Link to comment https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002550 Share on other sites More sharing options...
kla0005 Posted January 27, 2010 Author Share Posted January 27, 2010 Use preg_replace_callback or use the /e modifier. Can you write the full code for me? I dont know the function, so .. :i Quote Link to comment https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002698 Share on other sites More sharing options...
newbtophp Posted January 27, 2010 Share Posted January 27, 2010 Use preg_replace_callback or use the /e modifier. Can you write the full code for me? I dont know the function, so .. :i function replace_br($input){ $text = str_replace("<br />","", $input[1]); $ret = '<div class="code"><pre class="brush: php;">'.$text.'</pre></div>'; return $ret; } $turtorial = stripslashes(nl2br($foresp['turtorial'])); $turtorial = preg_replace_callback("/\\[ code\\](.+?)\[\/code\]/is", "replace_br", $turtorial); echo $turtorial; Quote Link to comment https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002718 Share on other sites More sharing options...
kla0005 Posted January 27, 2010 Author Share Posted January 27, 2010 Ehm.. Dude? I dont get it .. Can u write the full code, with replace_br function and that stuff - Please? Quote Link to comment https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002719 Share on other sites More sharing options...
kla0005 Posted January 27, 2010 Author Share Posted January 27, 2010 Well, now it looks better, but it still dosent work.. Now nothing happens?.. Text comes, but only the [ code] and that.. No transform.. And how can u make $input get something, if u dosent set anything in it? ", "replace_br", $ <-- Shouldent that be something like : ", replace_br('\1'), $ <-- I tryed this one, it didn't work - but still. Quote Link to comment https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002724 Share on other sites More sharing options...
kla0005 Posted January 27, 2010 Author Share Posted January 27, 2010 Well, it works now - Thanks ALOT! =D .. The problem was just my stupidity.. I forgot to remove the space in the [ code .. So.. BUT THANKS! =D Quote Link to comment https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002727 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.