Avatar of coolguy2009
coolguy2009
 asked on

need php script

I need a small php script that will get all of the links (everything between the "<a href=''>link_name</a>".

I need all links on the page in an associative array where the name is the 'link_name' and the value is the entire "<a href=''>link_name</a>".

link_name1 <a href=''>link_name1</a>
link_name2 <a href=''>link_name2</a>
link_name3 <a href=''>link_name3</a>
link_name4 <a href=''>link_name4</a>
link_name5 <a href=''>link_name5</a>
PHP

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
Lukasz Chmielewski

this for a start for a link itself
http://www.webmasterworld.com/forum88/6140.htm
Ray Paseur

Hey, coolguy2009.  This will grab all the links.  With a little work, it could be turned into an associative array.  Does that help any? ~Ray
<?php // RAY_graburls.php
if (empty($_GET["u"])) {
?>
<form action="<?=$PHP_SELF?>" method="get">
URL (like http://www.google.com):
<input type="text" name="u" />
<input type="submit" name="_submit" value="go" />
</form>
<?php
} else {
	$url	= $_GET["u"];
	$html	= file_get_contents($url);
	$html	= strip_tags($html, "<a><img>");
	preg_match_all("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $html, $matches, PREG_SET_ORDER);
	foreach ($matches as $value) {
		$link = htmlentities($value[0]);
		echo "<br />$link \n";
	}
}
?>

Open in new window

ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61