Log in

View Full Version : Replacing text in a message with an HMTL snippet


MTGDarkness
05-12-2009, 02:30 PM
I want to make certain words in messages on my forum be surrounded by HTML. For example, if a member types "magic" in to their message, that will be surrounded by (parsing) h2 tags automatically. Is this possible?

Lynne
05-12-2009, 03:02 PM
write a plugin to do a str_replace in the message. Do a search on that in these forums - the plugin has been posted before.

MTGDarkness
05-12-2009, 03:26 PM
In postbit_display_complete:

$post['message'] = str_replace('magic', '<h2 class="emphasis">magic</h2>', $post['message']);
$post['message'] = str_replace('Magic', '<h2 class="emphasis">Magic</h2>', $post['message']);

It does exactly what it's supposed to do.
Any idea how to make an h2 tag not start a new line? :p

Lynne
05-12-2009, 03:38 PM
h2 tags are block display tags by definition. They will start a new line unless you change their definition in your css.

MTGDarkness
05-12-2009, 03:47 PM
I was mostly joking. Is that possible? If so, how?

Lynne
05-12-2009, 04:52 PM
You modify the display property in your css for your h2 tags - http://www.w3schools.com/css/pr_class_display.asp

MTGDarkness
05-12-2009, 05:18 PM
That did it. Thanks a bunch. :) And removing the automatic bolding added to h2 tags?

RLShare
05-12-2009, 05:25 PM
Same thing, modify the CSS.

MTGDarkness
05-12-2009, 06:03 PM
Got it.

Andrewsha
05-16-2009, 06:54 PM
In postbit_display_complete:

Hello!
Please tell me where and how to find postbit_display_complete?

Can't find it in templates...

I understand it's some hook but it's not clear for me how to work with it.

EagleNick
05-16-2009, 09:04 PM
write a plugin to do a str_replace in the message. Do a search on that in these forums - the plugin has been posted before.
Couldn't you have just used a replacement variable?

Lynne
05-17-2009, 02:37 AM
I never use replacement variables if I only want to replace things in the post text. Replacement variables affect things *everywhere* and sometimes that screws things up big time.

EagleNick
05-17-2009, 12:10 PM
I never use replacement variables if I only want to replace things in the post text. Replacement variables affect things *everywhere* and sometimes that screws things up big time.
Does the str_replace only replace exact matches like replacement variables do?
For example, if I set up a str_replace to replace "The Black Cat" with "The White Cat" will it also replace instances of just "cat" or just "white" to "the white cat"?

Lynne
05-17-2009, 01:50 PM
str_replace replaces exact phrases. PHP Tutorial - str_replace (http://www.tizag.com/phpT/php-string-str_replace.php)

EagleNick
05-17-2009, 01:58 PM
Thank you Lynne. ;)

Andrewsha
05-18-2009, 05:37 AM
Hello!
Please help me to learn where to start defining postbit_display_complete hook.
Already I can make changes in templates but a point about hooks is not clear for me.

--------------- Added 1242643268 at 1242643268 ---------------

Found great guide https://vborg.vbsupport.ru/showthread.php?t=82625