开发者

How to strip html tags and leave link from a variable in php

How do I strip the HTML tags from a variable and leave the link? I am trying to send e开发者_运维百科mails with the link but without the tags. I've tried strip_tags(), but it removes the link.

$var = "this is a link <a href="mylink"/>yes it is</a>;

$message ="$var"; // email massage

How would I go about making it into "this is a link mylink yes it is"?


this could help you

$message = strip_tags(preg_replace('/<a href="(.*)">/', '$1', $var));


You can use regular expression to remove just tags, but not the link itself, if strip_tags does not work.


$regex  = '/<\/?[a-zA-Z0-9=\s\"\._]+>/';
preg_replace($regex,'',$mystring);

this will remove tags but leave it's contents. I'm not sure I've included all the necessary chars. you can add them later =)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜