Home  >  Article  >  Backend Development  >  PHP regular match specifies the beginning and end of the content & non-greedy mode

PHP regular match specifies the beginning and end of the content & non-greedy mode

巴扎黑
巴扎黑Original
2016-11-23 14:32:162114browse

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=&#39;My String <span class="infolist"><a class="info" href="http://www.xiaojudeng.com/">小桔灯信息网
adfadf
adsf
fgsdfg
</a></span><span>分类信息</span>&#39;; 
$string = preg_replace(&#39;/(<span class="infolist">).*?(<\/span>)/is&#39;, &#39;&#39;, $string); 
echo $string;
?>


Statement:
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
Previous article:php classes and objectsNext article:php classes and objects