Skip to content

Instantly share code, notes, and snippets.

@anisotropy
Last active October 12, 2016 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anisotropy/85914d931d4ee4fb3a8cbccfefb95134 to your computer and use it in GitHub Desktop.
Save anisotropy/85914d931d4ee4fb3a8cbccfefb95134 to your computer and use it in GitHub Desktop.
태그 사이에 있는 텍스트를 추출
<?php
$str = '<div class="a-class-name">some text</div>';
// PHP의 정규표현식은 구분자(delimiters)로 시작해서 구분자로 끝을 내야한다.
// 구분자는 보통 슬래쉬(/)를 사용하지만 꼭 그래야 하는 것은 아니고 해쉬(#)와 같이 알파벳과 백슬래쉬 그리고 공백이 아닌 문자를 사용하면 된다.
$pattern = '#<div class="a-class-name">(.*?)</div>#';
preg_match($pattern, $str, $matches);
echo $matches[1];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment