Skip to content

Instantly share code, notes, and snippets.

@voku
Last active October 17, 2018 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voku/48eabc060e9caefd58f15e13b5ef48d3 to your computer and use it in GitHub Desktop.
Save voku/48eabc060e9caefd58f15e13b5ef48d3 to your computer and use it in GitHub Desktop.
regex - remove first html tag
<?php
$input_lines = ' <div>da<a>
lalll
</a>sda
</div>';
$output = preg_replace('/^<(?<element_start>[a-z]+)(?<element_start_addon> [^>]*)?>(?<value>.*?)<\/(?<element_end>\1)>$/usi', '$3', trim($input_lines));
echo $output;
/*
da<a>
lalll
</a>sda
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment