在php中我们最常用的指定HTML标签可以直接使用strip_tags函数来替换了,利用它可以过滤所有的html标签哦,下面我来给大家介绍除了此函数之外的其它办法。
有时候我们需要把html标签页存到数据库里,但是有些场合却需要拿无html标签的纯数据,这个时候就要对带html标签的数据进行处理,把html标签都去掉,平时用 htmlspecialchars() 来过滤html,但是把html的字符转义了,最后显示出来的就是html源代码,利用strip_tags()就可以把html标签去除掉.
PHP默认的函数有移除指定html标签,名称为strip_tags,在某些场合非常有用。
strip_tags
strip_tags — Strip HTML and PHP tags from a string
string strip_tags ( string str [, string allowable_tags] )
弊端:这个函数只能保留想要的html标签,就是参数string allowable_tags,这个函数的参数allowable_tags的其他的用法,代码如下:
strip_tags($source,”); 去掉所以的html标签。
strip_tags($source,‘<div><img><em>’); 保留字符串中的div、img、em标签。
如果想去掉的html的指定标签,那么这个函数就不能满足需求了,于是乎我用到了这个函数,代码如下:
- function strip_only_tags($str, $tags, $stripContent = FALSE) {
- $content = '';
- if (!is_array($tags)) {
- $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
- if (end($tags) == '') {
- array_pop($tags);
- }
- }
- foreach($tags as $tag) {
- if ($stripContent) {
- $content = '(.+<!–'.$tag.'(–>|s[^>]*>)|)';
- }
- $str = preg_replace('#<!–?'.$tag.'(–>|s[^>]*>)'.$content.'#is', '', $str);
- }
- return $str;
- }
参数说明
$str — 是指需要过滤的一段字符串,比如div、p、em、img等html标签。
$tags — 是指想要移除指定的html标签,比如a、img、p等。
$stripContent = FALSE — 移除标签内的内容,比如将整个链接删除等,默认为False,即不删除标签内的内容。
使用说明,代码如下:
- $target = strip_only_tags($source, array(‘a’,'em’,'b’));移除$source字符串内的a、em、b标签。
- $source='<div><a href="" target="_blank"><img src="logo.png" border="0" alt="Welcome to linzl." />This a example from<em>lixiphp</em></a><strong>!</strong></div>
- ';
- $target = strip_only_tags($source, array('a','em'));
- //target results
- //<div><img src="/logo.png" border="0" alt="Welcome to lixiphp." />This a example from<strong>!</strong></div>
其它办法,代码如下:
- <?php
- //取出br标记
- function strip($str)
- {
- $str=str_replace("<br>","",$str);
- //$str=htmlspecialchars($str);
- return strip_tags($str);
- }
- ?>
一个自定义的函数,代码如下:
- **
- * 取出html标签
- *
- * @access public
- * @param string str
- * @return string
- *
- */
- function deletehtml($str) {
- $str = trim($str); //清除字符串两边的空格
- $str = strip_tags($str,"<p>"); //利用php自带的函数清除html格式。保留P标签
- $str = preg_replace("/t/","",$str); //使用正则表达式匹配需要替换的内容,如:空格,换行,并将替换为空。
- $str = preg_replace("/rn/","",$str);
- $str = preg_replace("/r/","",$str);
- $str = preg_replace("/n/","",$str);
- $str = preg_replace("/ /","",$str);
- $str = preg_replace("/ /","",$str); //匹配html中的空格
- return trim($str); //返回字符串
- }
波比源码 » PHP移除指定HTML标签方法总结
oral levaquin levofloxacin sale
buy anastrozole for sale buy anastrozole 1 mg for sale viagra over the counter
cialis 5mg generika tadalafil kaufen ohne rezept sildenafil 50mg kaufen ohne rezept
buy provigil 100mg pills provigil 100mg cheap order diamox 250 mg pill
order bupropion 150mg cetirizine 5mg drug seroquel medication
molnunat 200 mg oral naprosyn 250mg pill lansoprazole 15mg for sale
medroxyprogesterone 5mg ca oral cyproheptadine 4mg cyproheptadine 4 mg for sale
accutane over the counter buy generic prednisone 10mg prednisone 5mg ca
olanzapine brand buy valsartan 80mg sale valsartan 80mg sale
clozapine 50mg uk buy clozapine 50mg online cheap dexamethasone 0,0,5 mg drug
colchicine buy online online gambling jackpot party casino
zocor order order finasteride 5mg generic propecia drug
buy fluconazole 100mg without prescription sildenafil 150mg price viagra 100mg drug
cephalexin 125mg without prescription erythromycin 250mg cost buy erythromycin 250mg pills
order viagra 50mg for sale tadalafil drug cialis 10mg over the counter
oral desyrel 100mg buy suhagra generic aurogra cheap
buy naproxen 500mg generic omnicef usa lansoprazole 30mg tablet
brand biaxin 250mg clarithromycin 250mg canada buy antivert generic
buy proventil 100mcg albuterol 100 mcg for sale ciprofloxacin 500mg brand
order generic actos 15mg cost viagra sildenafil 200mg price
tadalafil 5mg drug Buy cialis in us real money casino games
real casino games blackjack online money free slot play
real money poker online best no deposit free spins online casino roulette
altace 10mg tablet amaryl 4mg sale cost etoricoxib 120mg
order doxycycline 100mg without prescription order ventolin 2mg online cheap cleocin ca
asacol 400mg usa mesalamine 800mg oral buy irbesartan 150mg generic
purchase temovate generic clobetasol order amiodarone us
acetazolamide 250mg usa imuran cost buy azathioprine 25mg generic
order generic alendronate 70mg buy alendronate 35mg pill order ibuprofen online
buy indomethacin 50mg for sale buy cenforce online cheap order cenforce 100mg generic
Thank you for great article. Hello Administ . Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
purchase famotidine sale order mirtazapine sale mirtazapine 15mg over the counter
buy requip 2mg generic buy trandate 100mg generic labetalol brand
tricor oral sildenafil citrate 50mg brand sildenafil 100mg
Good info. Lucky me I reach on your website by accident, I bookmarked it. Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
cheap cialis generic Buy cialis overnight delivery oral sildenafil 50mg
provigil ca order stromectol 6mg for sale promethazine us
prednisone 20mg tablet prednisone 5mg sale amoxil tablet
ivermectin human purchase stromectol generic prednisone brand
purchase zofran online cheap buy zofran 8mg order bactrim generic
Everything is very open and very clear explanation of issues. was truly information.
prednisolone 10mg price order prednisolone 40mg online cheap cost lasix
cheap provigil 100mg order provigil 200mg generic lopressor 100mg canada
purchase imuran pill order naproxen without prescription order generic naprosyn
sildenafil oral buy cialis next day delivery cialis 10mg without prescription
buy phenergan without prescription cheap promethazine 25mg cialis from india
order levofloxacin without prescription oral levaquin order bupropion 150mg online cheap
order warfarin 5mg pill order allopurinol 100mg without prescription buy zyloprim pill
lexapro oral prozac 40mg price buy naltrexone 50mg generic
order atorvastatin pills atorvastatin 40mg pills sildenafil 100mg pills for sale
buy letrozole 2.5mg online cheap sildenafil 100mg tablet buy sildenafil 50mg generic
tadalafil us cialis 10mg canada ed pills no prescription
buy ivermectin nz order stromectol 3mg pills buy isotretinoin 40mg pill
order modafinil 200mg online cost promethazine 25mg prednisone 10mg generic
cheap amoxil online azithromycin order online prednisolone 40mg ca
accutane for sale buy generic azithromycin over the counter azithromycin 500mg for sale
buy prednisolone 10mg pills prednisolone 40mg uk lasix 100mg tablet
buy albuterol tablets brand synthroid 150mcg synthroid 100mcg cost
buy clomid for sale order levitra 20mg generic cost hydroxychloroquine 200mg
buy doxycycline no prescription generic clavulanate augmentin 1000mg us
buy levothyroxine medication buy vardenafil sale vardenafil 10mg for sale
metformin 1000mg price order atorvastatin 20mg online amlodipine 5mg for sale
praziquantel where to buy order biltricide 600mg sale cyproheptadine order online
order lisinopril 5mg online buy zestril 5mg online order metoprolol pill
buy cheap generic pregabalin priligy for sale dapoxetine 90mg without prescription
cost xenical oral xenical 60mg allopurinol 300mg sale
imitrex 50mg drug order avodart online order avodart 0.5mg sale
buy generic sumycin over the counter order cyclobenzaprine online cheap ozobax price
order ranitidine 300mg order ranitidine 150mg pill celecoxib 200mg drug
order generic plavix 75mg buy luvox for sale purchase nizoral sale
flomax 0.2mg cheap buy zofran paypal order aldactone 100mg online
buy duloxetine 20mg for sale cheap cymbalta 20mg piracetam 800 mg pills
betnovate 20gm generic generic betamethasone sporanox 100 mg generic
brand combivent order linezolid 600 mg without prescription buy zyvox 600 mg sale
progesterone buy online buy cheap prometrium buy olanzapine 10mg online cheap
starlix 120 mg tablet order generic capoten 25 mg candesartan cheap
bystolic 5mg cheap buy bystolic 20mg pills clozaril 100mg pill
purchase simvastatin online cheap valtrex 500mg drug buy sildenafil 50mg online
tadalafil 20mg over the counter tadalafil 5mg ca viagra 50 mg
cefadroxil 250mg for sale order proscar 1mg pills propecia 5mg canada
buy fluconazole 100mg generic cipro 1000mg canada cheap ciprofloxacin 500mg
buy vermox online cheap tadalis medication tadalis canada
cleocin 150mg without prescription order generic erythromycin oral sildenafil 50mg
indocin 50mg sale buy indocin generic order cefixime generic
buy nolvadex 20mg online buy generic tamoxifen over the counter buy cheap generic ceftin
buy minocin 100mg generic order minomycin generic order pioglitazone 30mg online
buy isotretinoin 20mg pills azithromycin cost buy cheap azithromycin
ivermectin 12mg pills stromectol canada buy prednisone sale
azithromycin online buy buy generic prednisolone for sale order gabapentin online cheap
buy furosemide online diuretic order generic furosemide ventolin 4mg tablet
how to buy ramipril glimepiride price buy etoricoxib no prescription
levitra generic vardenafil for sale online order hydroxychloroquine 200mg generic
buy generic levitra buy zanaflex pills for sale buy hydroxychloroquine online
asacol 800mg drug buy astelin 10 ml for sale buy cheap generic avapro
order clobetasol buy cheap generic amiodarone amiodarone 200mg drug
cheap acetazolamide 250 mg buy generic imuran online azathioprine uk
lanoxin where to buy telmisartan for sale buy molnunat 200 mg generic
buy naprosyn generic buy lansoprazole 15mg without prescription generic prevacid 30mg
coreg for sale coreg 6.25mg uk purchase chloroquine generic
order montelukast 5mg generic symmetrel 100mg pill dapsone 100 mg drug
purchase baricitinib online olumiant sale buy generic atorvastatin over the counter
buy adalat online allegra uk buy fexofenadine pills for sale
buy norvasc tablets purchase amlodipine sale buy omeprazole generic
buy diltiazem medication zyloprim pills zyloprim 300mg pill
purchase triamcinolone pills generic clarinex buy claritin for sale
buy crestor medication purchase rosuvastatin sale motilium canada
sumycin 500mg price tetracycline 250mg over the counter ozobax cheap
buy clopidogrel tablets purchase methotrexate without prescription buy coumadin paypal
buy budesonide generic order cefuroxime for sale bimatoprost order online
buy topamax 200mg without prescription levaquin 250mg ca buy levofloxacin 250mg pills
methocarbamol 500mg cost purchase trazodone for sale how to get suhagra without a prescription
proscar 1mg tablet sildenafil fast shipping sildenafil 100mg usa
order divalproex 500mg generic order diamox 250 mg pills buy isosorbide sale
order imuran pills buy imuran generic how to get telmisartan without a prescription
meclizine usa minocin 100mg us minocin ca
movfor order online purchase naproxen sale cefdinir 300mg pill
male ed drugs sildenafil 100mg pills us pharmacy viagra
buy generic allegra over the counter buy generic glimepiride online glimepiride price
brand etoricoxib 120mg mesalamine uk azelastine 10ml ca
hytrin brand order arava online order cialis for sale
buy avapro pills order irbesartan 300mg generic buy generic buspirone
amiodarone pills coreg sale phenytoin cost
buy albendazole order medroxyprogesterone online provera 10mg tablet
where to buy praziquantel without a prescription order cyproheptadine order periactin 4 mg generic
buy oxybutynin 5mg for sale ditropan 5mg sale alendronate 35mg ca
order fluvoxamine 50mg generic purchase ketoconazole online order cymbalta generic
buy glipizide 5mg generic piracetam oral purchase betnovate without prescription
purchase anafranil for sale prometrium 100mg brand cost progesterone
order acetaminophen for sale generic panadol 500mg order pepcid 20mg sale
buy tinidazole 500mg sale purchase tindamax online buy nebivolol paypal
buy generic tacrolimus order remeron 15mg requip usa
buy valsartan pills for sale clozapine online buy combivent generic
trileptal 600mg tablet how to buy trileptal actigall 300mg us
captopril 25mg usa order atacand generic order carbamazepine 200mg without prescription
order ciplox 500mg sale brand lincomycin 500 mg order duricef 500mg online
combivir pills buy combivir oral accupril
frumil 5 mg pill cost clindamycin where to buy acivir without a prescription
purchase fluoxetine generic prozac 40mg ca purchase letrozole sale
cheap valcivir brand bactrim 960mg floxin for sale online