Parsing and sending text separately to another file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cobar
Forum Newbie
Posts: 3
Joined: Thu Jun 25, 2009 4:14 pm

Parsing and sending text separately to another file

Post 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.
User avatar
Kastor
Forum Newbie
Posts: 24
Joined: Thu May 01, 2008 2:29 am
Location: Grodno, Belarus
Contact:

Re: Parsing and sending text separately to another file

Post 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');
}
 
Post Reply