IT News/PHP

php 태그와 태그 속의 값 분리하여 처리하기 예제 - preg_match_all 함수

skyLove1982 2011. 1. 15. 14:11
반응형

php 태그와 태그 속의 값 분리하여 처리하기 예제 - preg_match_all 함수

<?php
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
    "<b>example: </b><div align=left>this is a test</div>",
    $out, PREG_PATTERN_ORDER);
echo $out[0][0] . ", " . $out[0][1] . "\n";
echo $out[1][0] . ", " . $out[1][1] . "\n";
?>

The above example will output:

<b>example: </b>, <div align=left>this is a test</div>
example: , this is a test


So, $out[0] contains array of strings that matched full pattern, and $out[1] contains array of strings enclosed by tags.



http://kr.php.net/manual/en/function.preg-match-all.php

반응형