note 102589 modified in function.preg-replace by danbrown

From: Date: Wed, 23 Feb 2011 15:48:10 +0000
Subject: note 102589 modified in function.preg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177252@lists.php.net to get a copy of this message
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

« previous php.notes (#177252) next »