Search code examples
javascripthtmlregextextwysiwyg

WYSIWYG without the HTML tags?


Is it possible to take only the text from WYSIWYG editor? For example, if you have the following text:

<a href="whatever"> sdadsa<>,.<> <p </a>

is it possible to take only the text inside the sdadsa<>,.<>?

Some might say don't use the editor but i need it to make two copies one with the tags and the other without HTML tags and only HTML tags that they match.

Is it possible to take the text without the HTML tags?


Solution

  • If you want to strip all HTML tags out of the output, you have two methods:

    • With PHP - use strip_tags($output).

    • With Javascript - type

      var plaintext= editorOutput.replace(/(<([^>]+)>)/ig,"");

      or use php.js's equivalent to the PHP method.