Last active
September 29, 2018 15:37
-
-
Save tieutantan/98d3787f3bbd869e1eef77b60a36bf4b to your computer and use it in GitHub Desktop.
PHP Regex patterns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Remove attributes of HTML tag | |
$data = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', $data); | |
// Remove empty HTML tag | |
$data = preg_replace('#<([^ >]+)[^>]*>([[:space:]]| )*</\1>#', '', $data); | |
// Remove non unicode character | |
$data = preg_replace('/[^\00-\255]+/u', '', $data); | |
// Replace multiple space with single | |
$data = preg_replace("/[\pZ\pC]+/u", " ", $data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment