codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<? $html = '<p>'; $html.= '<img src="story_img.jpg" width=120 height=80>'; $html.= 'In the last couple of weeks I often had to download a lot '; $html.= 'of files, submitted to a web-based teaching platform. Downloading '; $html.= 'all these files by hand is very annoying so I implemented a short '; $html.= 'Groovy script. Since Groovy has a great support for parsing well-'; $html.= 'formed XML-like information it fails if you want to parse '; $html.= 'unstructured and nasty HTML code.'; $html.= '</p>'; $doc = new DOMDocument(); $doc->loadHTML($html); $p = $doc->getElementsByTagName('p')->item(0); $img = $doc->getElementsByTagName('img')->item(0); $imgOfText = $img->getAttribute('src'); $TextWithOutImg = $p->nodeValue; echo "img url : ".$imgOfText."\n"; echo "text: ".$TextWithOutImg;
Private
[
?
]
Run code
Submit