Page 1 of 1

Parsing and sending text separately to another file

Posted: Sat Oct 17, 2009 5:21 am
by cobar
Hi

I have a file that contains a list of links in text, like this
htxp://forums.devnetwork.net/11
htxp://forums.devnetwork.net/1
without the x

The page source code looks like this

Code: Select all

<link>http://forums.devnetwork.net/11</link><br/>
<link>http://forums.devnetwork.net/1</link><br/>
I want to parse the text and send each link to another script, but I don't know how to do this, could you help me.

Re: Parsing and sending text separately to another file

Posted: Sat Oct 17, 2009 12:06 pm
by Kastor

Code: Select all

 
$contents = "
    <link>http://forums.devnetwork.net/a</link><br/>
    <link>http://forums.devnetwork.net/b</link><br/>
";
$links = array();
 
if (preg_match_all("/<link>([^<]+)(<\/link>)?<br\/>/", $contents, $matches)) {
    foreach ($matches[1] as $link) $links[] = $link;
} else {
    die('Error');
}