How to extract html tags from a string
Normally in the server side you could use a series of PHP functions (such as Show 1. Create a temporary DOM element and retrieve the textThis is the preferred (and recommended) way to strip the HTML from a string with Javascript. The content of a temporary div element, will be the providen HTML string to strip, then from the
The only problem of this (and the advantage) is that the browser will handle the providen string as HTML, that means that if the HTML string contains some type of interpretable Javascript for the browser, then it will be executed:
Therefore, you should use this only if you trust the source of the HTML string. 2. If you are using jQueryIf you use jQuery you can simplificate the code from the first step. The following code will do the same that the code in the first step (the warnings apply too):
|