Skip to content

Instantly share code, notes, and snippets.

@ekka21
Created August 8, 2012 02:47
Show Gist options
  • Save ekka21/3291612 to your computer and use it in GitHub Desktop.
Save ekka21/3291612 to your computer and use it in GitHub Desktop.
php: regular expression regex
If you would like to remove a tag along with the text inside it then use the following code.
<?php
preg_replace('/(<tag>.+?)+(<\/tag>)/i', '', $string);
?>
example
<?php $string='<span class="normalprice">55 PKR</span>'; ?>
<?php
$string = preg_replace('/(<span class="normalprice">.+?)+(<\/span>)/i', '', $string);
?>
This will results a null or empty string.
<?php
$string='My String <span class="normalprice">55 PKR</span>';
$string = preg_replace('/(<span class="normalprice">.+?)+(<\/span>)/i', '', $string);
?>
This will results a " My String"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment