New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesAre there methods in core API to sanatize text?Are there methods in core API to sanatize text?
Previous
 
Next
New Post
3/22/2011 8:44 PM
 
Hi,

I'm coding a module in C# and was wondering if there are core functions for sanitizing text?

I'd like the following title: "This is the title of the article" to be transformed into "this-is-the-title-of-the-article"

Regular expressions are not my strong point....  :-)

For example, in wordpress there is a function that takes a string - strips the html tags, transforms accented characters to normal characters etc.

        function sanitize_title_with_dashes($title) {

            $title = strip_tags($title);

            // Preserve escaped octets.

            $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);

            // Remove percent signs that are not part of an octet.

            $title = str_replace('%', '', $title);

            // Restore octets.

            $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);

            if (seems_utf8($title)) {

                if (function_exists('mb_strtolower')) {

                    $title = mb_strtolower($title, 'UTF-8');

                }

                $title = utf8_uri_encode($title, 200);

            }

            $title = strtolower($title);

            $title = preg_replace('/&.+?;/', '', $title); // kill entities

            $title = str_replace('.', '-', $title);

            $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);

            $title = preg_replace('/\s+/', '-', $title);

            $title = preg_replace('|-+|', '-', $title);

            $title = trim($title, '-');

            return $title;

        }


Colin Mulcahy
E: colin_mulcahy@hotmail.com
 
New Post
3/22/2011 9:08 PM
 
Not as such - but there are many c# sample code items around the web that could easily be incorporated into your module.
Or you could translate the wordpress function into c# very easily.

Westa
 
New Post
3/23/2011 3:50 AM
 
Colin

It looks like this core function can be fine for you StripNonWord. We have used it a lot in the Pages Administration and it works fine. Also Core uses it for Tabs Updating.

Hope this helps!

Sergey
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesAre there methods in core API to sanatize text?Are there methods in core API to sanatize text?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.