note 102589 modified in function.preg-replace by danbrown
[email protected] Wed, 23 Feb 2011 07:48:10 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
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"
--was--
If you would like to remove a tag along with the text inside it then use the following code.
preg_replace('/(<tag>.+?)+(<\/tag>)/i', '', $string);
example
$string='<span class="normalprice">55 PKR</span>';
$string = preg_replace('/(<span class="normalprice">.+?)+(<\/span>)/i', '', $string);
This will results a null or empty string.
$string='My String <span class="normalprice">55 PKR</span>';
$string = preg_replace('/(<span class="normalprice">.+?)+(<\/span>)/i', '', $string);
This will results a " My String"
http://php.net/manual/en/function.preg-replace.php