简体   繁体   English

Joomla | 如何过滤包含html标记的输入字符串

[英]Joomla | How to filter input string containing html tags

I have a joomla component and trying to filter HTML content from the users input. 我有一个joomla组件,并尝试从用户输入中过滤HTML内容。

$input  = $app->input->post->getRaw('question');

This will getting me the RAW html. 这将使我获得RAW html。

How can I check (The joomla way or custom php function) is it safe before saving into my database? 在保存到数据库之前,如何检查(joomla方式或自定义php函数)是否安全?

Thanks! 谢谢!

Joomla has an automatic function for that, please check System -> Global Configuration -> Text Filters and set the appropriate filtering for your user group. Joomla具有自动功能,请检查System -> Global Configuration -> Text Filters并为您的用户组设置适当的过滤System -> Global Configuration -> Text Filters

If you want to do that with php, you could use strip_tags() function. 如果要使用php进行操作,则可以使用strip_tags()函数。 Your result would be like: 您的结果将是:

$input  = strip_tags($app->input->post->getRaw('question'));

Good Luck! 祝好运!

You can convert the input to a string, striping all HTML tags/attributes, this way: 您可以通过以下方式将输入转换为字符串,剥离所有HTML标记/属性:

$jinput = JFactory::getApplication()->input;
$input = $jinput->get('question', 'default_value', 'html');

Official Documentation: Retrieving request data using JInput 官方文档: 使用JInput检索请求数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP DomDocument-如何追加包含html标签的字符串? - PHP DomDocument - how to append string containing html tags? 如何在Joomla中插入HTML标记!模块标题? - How to insert HTML tags in Joomla! module title? 如何将包含HTML标记和php变量的字符串转换为php字符串变量? - How to take a string containing HTML tags and php variables into a php string variable? 如何下载包含HTML标签的csv文件 - How to dowload csv file containing HTML tags 包含带有PHP标签的HTML的字符串,执行PHP并注入HTML - String containing HTML with PHP tags, execute the PHP and inject into the HTML PHP拆分包含html标签的字符串,并将字符串拆分为数组 - PHP split string containing html tags and split string into array 如何在joomla组件中使用jform为输入字段创建动态名称标签 - how to create dynamic name tags for input fields with jform in a joomla component 带有html标记的字符串将成为隐藏类型输入中的值 - string with html tags to be values in hidden type input 如何在html输入的字符串中过滤掉两个数字 - How to Filter Out two number in a string input on html 如何<a>从tha输出字符串中</a>删除<a>和所有其他html标签而不是在PHP中输入字符串时?</a> - how to Remove <a> and all other html tags from tha output string not at the time of input string in PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM