자신이 정규식에 자신있다! 봐주이소~! 정보
PHP 자신이 정규식에 자신있다! 봐주이소~!본문
<img src="이미지">
<area shape=RECT target=_blank coords=4,5,129,45 href="http://www.naver.com">
<area shape=RECT target=_blank coords=430,69,582,106 href="http://www.gmail.com/ ">
<area shape=RECT target=_blank coords=17,328,200,411 href=" http://www.naver.com ">
<area shape=RECT target=_blank coords=19,456,477,496 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=18,500,574,534 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=17,589,201,666 href="http://www.naver.com">
<area shape=RECT target=_blank coords=209,586,388,667 href="http://www.naver.com ">
<area shape=RECT target=_blank coords=401,585,594,669 href=" http://www.naver.com">
위를 보시면 href= 부분에 공백이 있는 것도 있구 없는것두 있어요
저는 href="주소" 에서 주소에 ltrim, rtirm 을 주고싶습니다
정규식을 이용해야 하는데 역시 제 머리론 정규식 어렵네요
정규식 고수님들을 답변좀~주이소 ㅠㅠ
<area shape=RECT target=_blank coords=4,5,129,45 href="http://www.naver.com">
<area shape=RECT target=_blank coords=430,69,582,106 href="http://www.gmail.com/ ">
<area shape=RECT target=_blank coords=17,328,200,411 href=" http://www.naver.com ">
<area shape=RECT target=_blank coords=19,456,477,496 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=18,500,574,534 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=17,589,201,666 href="http://www.naver.com">
<area shape=RECT target=_blank coords=209,586,388,667 href="http://www.naver.com ">
<area shape=RECT target=_blank coords=401,585,594,669 href=" http://www.naver.com">
위를 보시면 href= 부분에 공백이 있는 것도 있구 없는것두 있어요
저는 href="주소" 에서 주소에 ltrim, rtirm 을 주고싶습니다
정규식을 이용해야 하는데 역시 제 머리론 정규식 어렵네요
정규식 고수님들을 답변좀~주이소 ㅠㅠ
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
추천
0
0
댓글 4개
<?
$s =<<<HTMLCODE
<img src="이미지">
<area shape=RECT target=_blank coords=4,5,129,45 href="http://www.naver.com">
<area shape=RECT target=_blank coords=430,69,582,106 href="http://www.gmail.com/ ">
<area shape=RECT target=_blank coords=17,328,200,411 href=" http://www.naver.com ">
<area shape=RECT target=_blank coords=19,456,477,496 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=18,500,574,534 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=17,589,201,666 href="http://www.naver.com">
<area shape=RECT target=_blank coords=209,586,388,667 href="http://www.naver.com ">
<area shape=RECT target=_blank coords=401,585,594,669 href=" http://www.naver.com">
HTMLCODE;
$src = array("/=\"\s/", "/\s\"\>/");
$tar = array("=\"", "\">");
$s = preg_replace($src, $tar, $s);
?>
<textarea rows=10 cols=100><?=$s?></textarea>
$s =<<<HTMLCODE
<img src="이미지">
<area shape=RECT target=_blank coords=4,5,129,45 href="http://www.naver.com">
<area shape=RECT target=_blank coords=430,69,582,106 href="http://www.gmail.com/ ">
<area shape=RECT target=_blank coords=17,328,200,411 href=" http://www.naver.com ">
<area shape=RECT target=_blank coords=19,456,477,496 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=18,500,574,534 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=17,589,201,666 href="http://www.naver.com">
<area shape=RECT target=_blank coords=209,586,388,667 href="http://www.naver.com ">
<area shape=RECT target=_blank coords=401,585,594,669 href=" http://www.naver.com">
HTMLCODE;
$src = array("/=\"\s/", "/\s\"\>/");
$tar = array("=\"", "\">");
$s = preg_replace($src, $tar, $s);
?>
<textarea rows=10 cols=100><?=$s?></textarea>
이거 같은 경우는 항상 "로 쌓여있다는 가정하에 본다면
e 를 사용하여 처리하면 될것같습니다.
<?
$s =<<<HTMLCODE
<img src="이미지">
<area shape=RECT target=_blank coords=4,5,129,45 href="http://www.naver.com">
<area shape=RECT target=_blank coords=430,69,582,106 href="http://www.gmail.com/ ">
<area shape=RECT target=_blank coords=17,328,200,411 href=" http://www.naver.com ">
<area shape=RECT target=_blank coords=19,456,477,496 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=18,500,574,534 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=17,589,201,666 href="http://www.naver.com">
<area shape=RECT target=_blank coords=209,586,388,667 href="http://www.naver.com ">
<area shape=RECT target=_blank coords=401,585,594,669 href=" http://www.naver.com">
HTMLCODE;
$s = preg_replace("`href\s*=\s*\"(.+)\"`iUe", "'href=\"'.trim('\\1').'\"'", $s);
?>
<textarea rows=10 cols=100><?=$s?></textarea>
e 를 사용하여 처리하면 될것같습니다.
<?
$s =<<<HTMLCODE
<img src="이미지">
<area shape=RECT target=_blank coords=4,5,129,45 href="http://www.naver.com">
<area shape=RECT target=_blank coords=430,69,582,106 href="http://www.gmail.com/ ">
<area shape=RECT target=_blank coords=17,328,200,411 href=" http://www.naver.com ">
<area shape=RECT target=_blank coords=19,456,477,496 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=18,500,574,534 href=" http://www.naver.com">
<area shape=RECT target=_blank coords=17,589,201,666 href="http://www.naver.com">
<area shape=RECT target=_blank coords=209,586,388,667 href="http://www.naver.com ">
<area shape=RECT target=_blank coords=401,585,594,669 href=" http://www.naver.com">
HTMLCODE;
$s = preg_replace("`href\s*=\s*\"(.+)\"`iUe", "'href=\"'.trim('\\1').'\"'", $s);
?>
<textarea rows=10 cols=100><?=$s?></textarea>
$out1 = preg_replace("/(<area[^>]*href=[\"']?)\s*([^>\"'\s]+)\s*([\"']?[^>]*>)/i", "\${1}\${2}\${3}", $s);
echo "<xmp>";
print_r($out1);
echo "</xmp>";
echo "<xmp>";
print_r($out1);
echo "</xmp>";