The strip_tags() and wordwrap() functions in PHP are used to manipulate strings by removing HTML tags and wrapping long lines of text, respectively.
strip_tags() – Removes HTML and PHP tags from a string.wordwrap() – Wraps a string to a given number of characters, inserting line breaks.strip_tags(string, allowed_tags) cleans unwanted markup.wordwrap(string, width, break, cut) improves text readability.
// Remove all HTML tags and keep only plain text
<?php
$string = "<h1>Welcome to PHP</h1><p>This is a paragraph.</p>";
$clean_text = strip_tags($string);
echo $clean_text;
?>
The HTML tags are stripped, leaving readable plain text without markup.
// Wrap long text at 40 characters with line breaks
<?php
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
$wrapped_text = wordwrap($text, 40, "<br>\n");
echo $wrapped_text;
?>
The text is broken into multiple lines at 40 characters, improving readability in HTML output.
Click the button to see how text wrapping improves readability by constraining the container width.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
strip_tags() to prevent unwanted HTML rendering.strip_tags().wordwrap().