Removing HTML Tags Using strip_tags(html)
¶
Overview¶
In many modules of Merciglobal Cloud ERP, data retrieved from the database or user inputs might contain HTML markup. To sanitize or display such data cleanly — particularly for logs, previews, or printable formats — it's necessary to remove HTML tags.
The strip_tags(html)
method is a reliable way to achieve this.
Purpose¶
- Ensure clean and readable content.
- Prevent unintended rendering of HTML tags.
- Safeguard against basic XSS vectors when displaying content.
- Useful for generating plain-text versions of rich-text fields (e.g., notes, descriptions, emails).
Use Cases in Merciglobal Cloud ERP¶
- Invoice Descriptions: Remove styling tags when exporting to CSV or plain PDFs.
- Email Previews: Show message previews without HTML formatting in the dashboard.
- Audit Logs: Store clean, readable actions without embedded tags.
- Search Indexing: Clean text improves indexing and search performance.
Example¶
HTML Input:¶
<p>Welcome to <strong>Merciglobal Cloud ERP</strong>! Please visit our <a href="/docs">Documentation</a>.</p>
Output After strip_tags(html)
:¶
Welcome to Merciglobal Cloud ERP! Please visit our Documentation.
Implementation¶
JavaScript Example:¶
function stripTags(html) {
var div = document.createElement("div");
div.innerHTML = html;
return div.textContent || div.innerText || "";
}
Security Notes¶
- Not a substitute for full HTML sanitization when security is a concern (use libraries like DOMPurify).
strip_tags()
does not decode HTML entities.
Tips¶
- Combine with
html_entity_decode()
if you want clean text. - Useful before storing logs or sending SMS alerts where rich formatting isn’t supported.
Conclusion¶
Using strip_tags(html)
ensures cleaner content and a more controlled display of information across Merciglobal Cloud ERP modules. It enhances both usability and security, making it an essential utility for both developers and business users.