Skip to content
Advertisement

Replace pairs of symbols in chat text with html tags to style as bold, italic, and strikethrough

I am trying to make a whatsapp style text post. When user create text like this:

JavaScript

then this text is automatically changing like this

Hi how are you where are you

I know i can do it with php regex like this:

The example is for bold text:

JavaScript

But there is a problem it should be remove * when text is outputed.

The other regex also should be like this:

Bold:

JavaScript

Italic:

JavaScript

strikethrough:

JavaScript

My question is, can I do all this in one regex? And can the special characters be deleted when the output is made?

Advertisement

Answer

You may use a single call to preg_replace_callback here:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement