Top

[PHP] REGULAR EXPRESSION EXAMPLE preg_replace, preg_match, str_replace | Web-Programing
(admin) | Editor | 2013/02/04 09:06:19 | ȸ:3497

 [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.com
http://
www.whitesal.com
ϱ
ϱ
0
0
0


ҷ Դϴ.
[PHP] Ϲ 迭 üũ! (admin) 2013-02-06 19:58:25
[PHP] ڿ Լ (admin) 2013-01-30 21:41:22