[Snippet] [Fix**] Html replacement in post text 3.2.*

[DEV] 3.2.* Mod Base

[Snippet] [Fix**] Html replacement in post text 3.2.*

Postby BNa » 15 Oct 2019, 23:56

Html replacement in post text

With this snippet you can use html as a kind of word censor in posts

Requested by: Mike3396
Request topic: http://www.phpbb.com/community/viewtopi ... &t=2157114

Instruction

open

includes/functions_content.php

find

Code: Select all
    $vars = array('text', 'uid', 'bitfield', 'flags');
    extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_after', compact($vars))); 


after add [Fix**]

Code: Select all
    // BNa
    
global $phpbb_root_path$phpEx;
    include(
$phpbb_root_path 'includes/functions_word_censors.' $phpEx); 


load up a file named functions_word_censors.php (utf8 without a bom) with following (test)-content to includes/functions_word_censors.php

Code: Select all
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
    exit;
}


// Here all Word-Censors // Just replace without any masking

$text = @preg_replace('#\bBanana\b#', '<span style="color:red; font-weight: bold;">Banana</span>', $text);
$text = @preg_replace('#\bBanan\b#', '<a href="http://www.google.de">Banan</url>', $text);
$text = @preg_replace('#\Bthinsp\B#', '&thinsp;', $text);

?>


Result for "Banana":
Image

Note

Edit Banana to any word with any html as replacement like <span style="color:red; font-weight: bold;">Banana</span>.

Leave all other syntax in place. Make as many "new lines" you want.

\b is for search > solo words > test (boundarys)
\B is for search > words in words like testthinsptest (not bounded)
User avatar
BNa

Tiptop

Tiptop
 
Posts: 17
Joined: 03 Jul 2011, 15:03
 
Resolution: 1920x1080

Return to phpbb 3.2.* St@ff

Who is online

Users browsing this forum: No registered users and 1 guest

cron