Jump to content

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002514
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002718
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/190011-remove-from-bbcode/#findComment-1002724
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.