note 102589 added to function.preg-replace
[email protected] Tue, 22 Feb 2011 21:57:35 -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.
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"
----
Server IP: 69.147.83.197
Probable Submitter: 119.152.32.7
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/102589
Del: integrated -- https://master.php.net/note/delete/102589/integrated
Del: useless -- https://master.php.net/note/delete/102589/useless
Del: bad code -- https://master.php.net/note/delete/102589/bad+code
Del: spam -- https://master.php.net/note/delete/102589/spam
Del: non-english -- https://master.php.net/note/delete/102589/non-english
Del: in docs -- https://master.php.net/note/delete/102589/in+docs
Del: other reasons-- https://master.php.net/note/delete/102589
Reject -- https://master.php.net/note/reject/102589
Search -- https://master.php.net/manage/user-notes.php