strip_tags
-
This function’s solution will only work within the context of the Rails framework.
Rails has a series of helpers to help sanitize output. These are all in ActionView’s
ActionView::Helpers::SanitizeHelpermodule. We can strip tags from text in Rails using thesanitizemethod which takes a list of optionaltagsorattributesas a whitelist.PHP
$content = "<strong>Test</strong> some <em>tags<em>"; $result = strip_tags($content, '<em>'); var_export($result); // => 'Test some <em>tags<em>'
Rails
# in app/views/posts/index.html.erb <% @text = "<strong>Test</strong> some <em>tags<em>" %> <%= sanitize(@text, :tags => %w(em), :attributes => %w(style)) %> # => "Test some <em>tags<em>"
Rails also has helpers to
sanitize_css,strip_tags,strip_linkssee also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

