Skip to content

Instantly share code, notes, and snippets.

@tieutantan
Last active September 29, 2018 15:37
Show Gist options
  • Save tieutantan/98d3787f3bbd869e1eef77b60a36bf4b to your computer and use it in GitHub Desktop.
Save tieutantan/98d3787f3bbd869e1eef77b60a36bf4b to your computer and use it in GitHub Desktop.
PHP Regex patterns
<?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:]]|&nbsp;)*</\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