0

It seems that my question is not well asked, that's why I am asking you to help me.

I have a chunk of html code when in <textarea> tag created with WYSIWYG editor.

Now before saving, on form submit, I would like to normalize the text inside by removing unneccessary whitespaces/spaces, have the code well formated with tabs, etc.

here is the code:

27 Июня
                 17:51:58                                                                                                                       Познакомлюсь с девчонками из прибалтики                                                 Категория: Знакомства > Контакты по интересам                                       Просмотров: 7

I wish this text is going in one row (single lined), but with correct use of spaces, dots etc. Is it possible somehow with PHP without need to write a function ?

2 Answers 2

2

Sanitizing text is never a task composed of just one line of text, I'm afraid. However, the procedures are somewhat common for simple cleansing. For example, $output = preg_replace("/\s+/", " ", $input); will get rid of excess whitespaces but I would worry a lot more about possible malicious code injections through that <textarea> element.

Maybe you should give HTMLPurifier a look, it's quite complete even if it's still not HTML5 compliant. It will sort out the majority of concerns about filtered content.

Hope that helps :)

Sign up to request clarification or add additional context in comments.

Comments

0

try giving striptags("string");

1 Comment

unfortunately that wasn't exactly what I was searching for, but thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.