Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // Remove all whitespace $clean = preg_replace("/\s+/", " ", $text); // Format phone number $formatted = preg_replace("/^(\d{3})(\d{3})(\d{4})$/", "($1) $2-$3", "5551234567"); // "(555) 123-4567" // Strip HTML tags (simplified) $plain = preg_replace("/<[^>]+>/", "", $html); // Replace multiple patterns at once $result = preg_replace( ["/foo/", "/bar/"], ["baz", "qux"], "foo and bar" ); // "baz and qux"
Result
Open