Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2008, 04:19 AM
speedway's Avatar
speedway speedway is offline
 
Join Date: Nov 2001
Location: Sydney, Australia
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP Help, Stripping HTML tags and updating MySQL.

Hi all

I am looking for a bit of help in PHP. For my forums DB, I want to programatically update every posts content with the same content minus all the HTML tags. Basically a small PHP app to

connect to Mysql,
open the post table,
extract the pagetext value,
strip all HTML tags from it
write it back to that record
loop to the next record.

Due to my distinct lack of PHP knowledge I am struggling with the looping bit and retrieve/modify/update bit, so I appreciate some kind soul showing me the right direction.

Thanks in advance

Cheers
Bruce
Reply With Quote
  #2  
Old 02-02-2008, 04:41 AM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

When the posts are brought out of the database they are script of all the html tags, etc if you have html turn off and bbcode code is added.
Reply With Quote
  #3  
Old 02-02-2008, 05:16 AM
speedway's Avatar
speedway speedway is offline
 
Join Date: Nov 2001
Location: Sydney, Australia
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MoT3rror View Post
When the posts are brought out of the database they are script of all the html tags, etc if you have html turn off and bbcode code is added.
Thanks but I am not concerned how they look on the page. I want to convert my DB to UTF-8 and there are problematic posts that have been pasted from Microsoft Word. These contain font tags, color tags, font size tags and weird character formatting that causes grief. I basically want to strip everything HTML related from every posts and then I can safely convert the contents to UTF-8.

Cheers
Bruce
Reply With Quote
  #4  
Old 02-02-2008, 08:31 AM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The 'post' table only stores the post with BBCode, unless you had HTML enabled on your board or something?
Reply With Quote
  #5  
Old 02-02-2008, 08:48 AM
speedway's Avatar
speedway speedway is offline
 
Join Date: Nov 2001
Location: Sydney, Australia
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Opserty View Post
The 'post' table only stores the post with BBCode, unless you had HTML enabled on your board or something?
Damn, see? Shows how much experience I have with this!

So, I need to remove all BBcode tags and restore the text to the Verdana, size 2 set. Any pointers to how I would do that - sites, texts, books, anything?

Cheers
Bruce
Reply With Quote
  #6  
Old 02-02-2008, 09:50 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You'll need some regex replacements. (I hate regex, as it's really confusing, but I'm giving it a shot .)
PHP Code:
$newtext preg_replace('/\[(.+?)]/'''$text); 
Reply With Quote
  #7  
Old 02-02-2008, 11:51 AM
speedway's Avatar
speedway speedway is offline
 
Join Date: Nov 2001
Location: Sydney, Australia
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you Sir.

Armed with that I went searching on Google and found this:

Code:
function stripBBCode($text_to_search) {
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
return preg_replace($pattern, $replace, $text_to_search);

}
but it zaps *all* BBCode. Would anyone have any idea on how to make it *not* remove things like:
[ QUOTE ]
[ /QUOTE ]
[ QUOTE=
[ B ]
[ I ]
[ U ]
or any of the other basic ones? (spaces included on purpose so the forum doesn't try and use them)

I did find this function as well:

Code:
function stripBBCode($stringInput) {
    if (strpos($stringInput, '[') !== false) {
        $validBBCodeArray = array(
            'b',
            'i',
            'u',
            'url',
            'quote',
        );
        
        $validBBCode = join('|', $validBBCodeArray);
        
        $stringOutput = preg_replace(
            '@\[(?:\/{0,1}?)(?:' . $validBBCode . ')(?:\s{0,1}?)(?:\/{0,1}?)\]@',
            '',
            $stringInput
        );
    } else {
        $stringOutput = $stringInput;
    }

    return $stringOutput;
}
but it strips everything *except* font and size tags (for some reason).

All the help so far is being appreciated I assure you. Now for that last little step

Cheers
Bruce
Reply With Quote
  #8  
Old 02-03-2008, 04:57 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this (it will strip all font and size tags, but nothing else):
PHP Code:
$newtext preg_replace('/\[(?:\/{0,1}?)(?:font|size)(?:\s{0,1}?)(?:\/{0,1}?)\]/'''$text); 
Reply With Quote
  #9  
Old 02-03-2008, 08:18 AM
speedway's Avatar
speedway speedway is offline
 
Join Date: Nov 2001
Location: Sydney, Australia
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Hanson

I tried that but it strips everything *but* the font & size tags I have tried nutting this one out myself but am still lost.

Cheers
Bruce
Reply With Quote
  #10  
Old 02-03-2008, 08:23 AM
Reecey Reecey is offline
 
Join Date: Dec 2007
Posts: 62
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

where do i put this code i would like to get rid of html used on my forum to as when i first opened many post's were made using html and i would prefer it to be bb code where do i put the code ?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:17 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07055 seconds
  • Memory Usage 2,260KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (2)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete