Home > Article > Backend Development > PHP regular match specifies the beginning and end of the content & non-greedy mode
php regular matches the specified start and end content, specifies the start and end position, extracts/matches the middle content, and returns the processed string content. Non-greedy mode is used
<?php /** * create by tuzwu@qq.com for 小桔灯www.xiaojudeng.com */ $string='My String <span class="infolist"><a class="info" href="http://www.xiaojudeng.com/">小桔灯信息网 adfadf adsf fgsdfg </a></span><span>分类信息</span>'; $string = preg_replace('/(<span class="infolist">).*?(<\/span>)/is', '', $string); echo $string; ?>