Created
August 8, 2012 02:47
-
-
Save ekka21/3291612 to your computer and use it in GitHub Desktop.
php: regular expression regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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