티스토리 뷰
$string = '한글<iframe src="http://www.youtu.be/dQw4w9WgXcQ"></iframe>dfjasdflajksl';
$pattern = 'src=["']?(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&"'>]+)["']?';
preg_match("/{$pattern}/i", $string, $matches);
echo ($matches[0]); //only the src="http://www.youtu.be/dQw4w9WgXcQ part
echo ($matches[1]); //the video id part. (dQw4w9WgXcQ)
참고
- http://stackoverflow.com/questions/6909405/filter-out-iframe-using-preg-match
- http://stackoverflow.com/a/17030234
'웹프로그래밍 > PHP' 카테고리의 다른 글
| macOS 용 docker 상의 php Xdebug 와 PHPStrom 연동 방법 (0) | 2016.11.15 |
|---|---|
| PHP 에서 UTC 날짜 KST 로 변환 (0) | 2016.11.09 |
| PHP utf-8 환경에서 euc-kr 비표준 특수문자 변환 해결 사례 (1) | 2016.03.17 |
| XE 페이지 문자 깨짐 발생시 (0) | 2016.03.11 |
| Lumen - L5 호환 - 시작하기 (0) | 2015.12.10 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- JQuery
- nodejs
- JSON
- javascript
- sencha touch
- Linux
- CSS
- Android
- laravel
- git
- API
- IE
- Prototype
- Wordpress
- iis
- 워드프레스
- classic asp
- Docker
- ASP
- IOS
- centos
- Mac
- Debug
- 안드로이드
- PHP
- macos
- mssql
- nginx
- 한글
- iphone
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
글 보관함