Jump to content

code help


quickstream

Recommended Posts

ok im working with subdreamer and installed a mod which interacts with a forum on my host so that news is shown on the front page, but i have a 20word limit so the bbcode is usually cut short which in turn messeges the whole row of news up (beyond the one article it is in)

 

soo i have tried to remove it i can eaily deactive the bbcode but i cannot remove the tags thus i introduce this code

 

$no_bbcode = explode(bbencode_second_pass($post['message'], $post['bbcode_uid']));
foreach ($no_bbcode as $nobbcode)
{
$post['message'] = eregi_replace($nobbcode, "", $post['message']);
} 

 

i have tried a few variations of this including

 

$no_bbcode = explode($post['bbcode_uid']);
foreach ($no_bbcode as $nobbcode)
{
$post['message'] = eregi_replace($nobbcode, "", $post['message']);
} 

 

&

 

$no_bbcode = explode('|','[b]|[/b]|[i]|[/i]|[u]|[/u]|[quote]|[/quote]|[code]|

||]|[list=]|

  • |

');

foreach ($no_bbcode as $nobbcode)

{

$post['message'] = eregi_replace($nobbcode, "", $post['message']);

} [/code]

 

non work as they should, i would have tried something like mysql_escape_string() but that wont effect bbcode will it?

 

lil help please im non a very good php code junky and im stil teaching myself but im genuinly stuck

Link to comment
Share on other sites

I'm not great with regular expression but here goes.

$post['message'] = preg_replace('@\[[\/\!]*?[^\[\]]*?\]@si', '', $post['message']);

 

soo

 

$post['message'] = preg_replace('[b], [/b], [i], [/i], etc?', '', $post['message']);

 

 

yes?, il try now but its a whole lot more simpler then my version, though i may add a new expression after this format has taken place so i can add a function in the admin panel to turn it on and off

Link to comment
Share on other sites

The one posted removes all matches of [] and [/ ] and anything contained within.

If you need more control over it try it this way

<?php
$search = array (
    '@([b])@i',    // remove bold start
    '@([/b[)@i',  //  remove bold end
    '@([i])@i',    //  remove italics start
    '@([/i])@i',   //  remove italics end
    '@([u])@i',   
    '@([/u])@i',
    '@([quote])@i',
    '@([/quote])@i'
); 
$replace = array ('', '', '', '', '', '', '', '');
$post['message'] = preg_replace($search, $replace, $post['message']);
?>

 

Add as many as you want just keep the two arrays balanced, but it seems simpler to remove them all at once...

 

Link to comment
Share on other sites

ok both code lines work the problem is with what im trying to exclude, the square brackets may be having a problem right in the code? is there a strip_something() varible i can use?

 

 

which has been brought up in the new post, so il try that code it looks very interesting and iv only just gone past that chapter in the book im reading to get a grasp of php keke

 

il let you know of the result if positive il resolve this thread

Link to comment
Share on other sites

non of these work without some kind of unwanted effect after a second try the array does the best it only leave the bbcode id but also had a side effect which pretty much makes all the messege spam such as "gfhjkdfshjkfhds",

 

i can remove bbcode id and here is the unwanted effect its not made it spam just removed the letters and spaces

untitled.jpg

Link to comment
Share on other sites

I'm not sure what you are looking for.

It removes the bbcode for me.

 

<?php
$_POST['message'] = '[b]Hello, [/b][i]hello, [/i][u]goodbye[/u]';
$_POST['message'] = preg_replace('@\[[\/\!]*?[^\[\]]*?\]@si', '', $_POST['message']);
echo htmlentities($_POST['message']);
?>

 

displays-> Hello, hello, goodbye

Link to comment
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.