Ok, here's the dealio
I have a string which has a load of <a href="http://domain.tld" title="detailed description">link text</a> style things in it, one per line
How would I extract:
1) the URL
2) the value of title attribute
3) the link text
I figured regular expressions are the way to go, but I'm a little confused on where to start!
Any pointers? I came up with this:
Which, while crude, does the job but it'd get messed up if there is no title attribute.
Thanks in advance,
MrJ
I have a string which has a load of <a href="http://domain.tld" title="detailed description">link text</a> style things in it, one per line
How would I extract:
1) the URL
2) the value of title attribute
3) the link text
I figured regular expressions are the way to go, but I'm a little confused on where to start!
Any pointers? I came up with this:
PHP:
<?php
function extractLink($link) {
$link = split("\n",trim($link));
for($i = 0; isset($link[$i]); $i++){
$link[$i] = explode("\"",$link[$i]);
$link[$i]['url'] = substr($link[$i][1],7);
$link[$i]['description'] = $link[$i][3];
$link[$i]['title'] = substr($link[$i][4],1);
$link[$i]['title'] = strrev(substr(strrev($link[$i]['title']),4));
}
for($i = 0; isset($link[$i]); $i++){
foreach($link[$i] as $key => $value){
if(is_numeric($key)){
unset($link[$i][$key]);
} else {
$link[$i][$key] = htmlentities($value);
}
}
}
return $link;
}
?>
Which, while crude, does the job but it'd get messed up if there is no title attribute.
Thanks in advance,
MrJ