[PHP] REGULAR EXPRESSION EXAMPLE preg_replace, preg_match, str_replace
</iframe> $STRING=preg_replace("!<iframe(.*?)</iframe>!is","",$STRING); script $STRING=preg_replace("!<script(.*?)</script>!is","",$STRING); meta $STRING=preg_replace("!<meta(.*?)>!is","",$STRING); style ± $STRING=preg_replace("!<style(.*?)</style>!is","",$STRING); ȯ $STRING=str_replace(" "," ",$STRING); ӵ 1 $STRING=preg_replace("/s{2,}/"," ",$STRING); ±ȿ style= Ӽ $STRING=preg_replace("/ style=([^"']+) /"," ",$STRING); // style=border:0... ǥ $STRING=preg_replace("/ style=("|')?([^"']+)("|')?/","",$STRING); // style="border:0..." ǥ ± width=, height= Ӽ $STRING=preg_replace("/ width=("|')?d+("|')?/","",$STRING); $STRING=preg_replace("/ height=("|')?d+("|')?/","",$STRING); img ± src preg_match("/<img[^>]*src=["']?([^>"']+)["']?[^>]*>/i",$STRING,$RESULT); preg_match_all("/<img[^>]*src=["']?([^>"']+)["']?[^>]*>/i",$STRING,$RESULT); ȣƮ <? preg_match("/^(http://)?([^/]+)/i","http://www.whitesal.com/index.html",$matches); $host = $matches[2]; echo$matches[0]."<br>"; echo$matches[1]."<br>"; echo$matches[2]."<br>"; ?> http://www.whitesal.comhttp:// www.whitesal.com |