正则初学者

WBOY
Release: 2016-06-13 11:12:13
Original
1046 people have browsed it

正则菜鸟求救
这里发言,表示您接受了CSDN论坛的用户行为准则
请对您的言行负责,并遵守中华人民共和国有关法律法规,尊重网上道德。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。

怎么把a标记去掉,只留下行为准则。小弟先谢谢了


------解决方案--------------------
 public function strip_selected_tags($text, $tags = array())<br />   {<br />       $args = func_get_args();<br />       $text = array_shift($args);<br />       $tags = func_num_args() > 2 ? array_diff($args,array($text))  : (array)$tags;<br />       foreach ($tags as $tag){<br />           if(preg_match_all('/<'.$tag.'[^>]*>(.*)<\/'.$tag.'>/iU', $text, $found)){<br />               $text = str_replace($found[0],$found[1],$text);<br />         }<br />       }<br /><br />       return $text;<br />   }<br />$text = '<a href="www.baidu.com">行为准则</a>的撒的发的是发烧的发的';<br />echo strip_tags($text);<br />echo strip_tags($text, '<a>');<br /><br />
Copy after login

------解决方案--------------------
给你个正则入门教程看看
http://www.regexlab.com/zh/regref.htm
------解决方案--------------------
正则就可以了,
$str='行为准则';
echo preg_replace("/(.*)/iU",'\2',$str);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!