일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 구글 클라우드
- Google Cloud
- Xdebug
- git pull
- Fail2ban
- Certbot
- centos
- https
- launch.json
- home page
- MariaDB
- root
- SSL
- new user
- crontab
- front page
- LetsEncrypt
- Apache
- CentOS7
- vscode
- Linux
- php
- Mac
- mysql
- DOM Parser
- child theme
- wordpress
- Liniux
- html
- non-www
- Today
- Total
between 0 and 1
PHP Simple HTML DOM Parser 링크 및 사용법 간단 정리 본문
PHP Simple HTML DOM Parser 링크 및 사용법 간단 정리
devxpert.yoon 2018. 7. 18. 07:06PHP Simple HTML DOM Parser
Link: http://simplehtmldom.sourceforge.net/
Usage:
// Include the library
include('simple_html_dom.php');
// Retrieve the DOM #1 - from a given URL
$html = file_get_html('https://davidwalsh.name/');
// Retrieve thd DOM #2 - from a file or string variable
$html = str_get_html($row->value);
// Find all "A" tags and print their HREFs
foreach($html->find('a') as $e) {
echo $e->href . '<br>';
}
// Retrieve all images and print their SRCs
foreach($html->find('img') as $e)
echo $e->src . '<br>';
// count all images
count($html->find('img'));
// get 0th img src
$imgSrc = $html->find('img',0)->src;
// change 0th img src
$html->find('img',0)->src = 'https://t1.daumcdn.net/tistory_admin/static/top/tistoryLogo.gif';
// get updated html data
$html->__toString();
// Find all images, print their text with the "<>" included
foreach($html->find('img') as $e)
echo $e->outertext . '<br>';
// Find the DIV tag with an id of "myId"
foreach($html->find('div#myId') as $e)
echo $e->innertext . '<br>';
// Find all SPAN tags that have a class of "myClass"
foreach($html->find('span.myClass') as $e)
echo $e->outertext . '<br>';
// Find all TD tags with "align=center"
foreach($html->find('td[align=center]') as $e)
echo $e->innertext . '<br>';
// Extract all text from a given cell
echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>';
'Software Development Engineering > PHP' 카테고리의 다른 글
[PHP, PDF] TCPDF 한글 깨짐 해결 방법 (0) | 2021.01.29 |
---|---|
[PHP] PHP + xDebug + vscode + Mac (BigSur+) (0) | 2021.01.03 |
[PHP] Request가 HTTP인지 HTTPS인지 확인하는 방법 (0) | 2018.07.21 |
var_dump(), 출력되는 문자열 길이 제한 풀기 (0) | 2018.07.20 |