[ create a new paste ] login | about

Link: http://codepad.org/eOa1ygpm    [ raw code | output | fork ]

PHP, pasted on Feb 22:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?
        $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;


Output:
1
2
img url : story_img.jpg
text: In the last couple of weeks I often had to download a lot of files, submitted to a web-based teaching platform. Downloading all these files by hand is very annoying so I implemented a short Groovy script. Since Groovy has a great support for parsing well-formed XML-like information it fails if you want to parse unstructured and nasty HTML code.


Create a new paste based on this one


Comments: