473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sort Script - Extract links, and sort (regex)

I have a script that will read web file, extract the hyperlinks and sort them in alphabetical order.

It works fine, but not the way I want.

I want to change the script so that it will extract the text link as well.

//sortlinks.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $matches= array();
  3.     $page = file_get_contents("reviews.htm");
  4.     $pattern = "/((?<=href=')).*?(?=')/i";
  5.     preg_match_all($pattern,$page,$matches);
  6.  
  7.     $links[] = $matches[0];
  8.  
  9.     sort($links);
  10.  
  11.     $nlinks = $links[0];
  12.     sort($nlinks);
  13.  
  14.     foreach ($nlinks as $l)
  15.         echo '<a href="' . $l . '">' . $l . "</a><br />\n";
  16. ?>
  17.  
//reviews.htm the comments are to let you know the url of the links.
- alink // directory/alink.htm
- clink // director/clink.htm
- blink // director/blink.htm

Right now, the output I'm getting is

directory/alink.htm
directory/blink.htm
directory/clink.htm

This is what I want (hyperlinks directing to their urls):
alink
blink
clink

I suspect we have to change something in $pattern.
I've tried a lot of things, but I keep getting errors.

Any help would be appreciated.

Thanks
Jan 23 '06 #1
1 6876
pbmods
5,821 Expert 4TB
Heya, kidkurious. Welcome (belatedly) to TSDN!

Check out basename().
Dec 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rock | last post by:
Hi, I started using a python based screen scraper called newsscraper I downloaded from sourceforge. http://sourceforge.net/projects/newsscraper/. I have created many python templates that work...
1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
8
by: bissatch | last post by:
Hi, I am about to create a table, where the values are taken from an XML file, where each column header you can click and it will sort the table rows at the client side. I have got to the...
1
by: livin | last post by:
I'm hoping someone knows of an example script I can see to help me build mine. I'm looking for an easy way to automate the below web site browsing and pull the data I'm searching for. Here's...
9
by: David | last post by:
Hi all, I have an array of strings. For example... = "entry1 first entry"; = "entry2 second entry"; = "entry3 third entry"; etc... How can I sort this array by the number after "entry"?
2
by: Thief_ | last post by:
I've got this type of info on a web page: ---------------------------------------------------------------------------- -------------------------------------------- <tr height="25"> <td nowrap...
13
by: Tony Girgenti | last post by:
Hello. Using VS.NET 2003 VB. If i have a string similar to the attached, how would i extract the "Truckname=" data from it in a loop and stay in the loop until the end of the string is reached...
9
by: Synapse Syndrome | last post by:
Hi I've been given what I am told is a PHP script to be used on my server. I do not know any PHP. I am trying to use a feature of a program called ArchiCAD. This feauture allows CAD drawing...
1
by: GS | last post by:
I need to extract sections out of a long string of about 5 to 10 KB, change any date format of dd Mmm yyyy to yyyy-mm-dd, then further from each section extract columns of tables. what is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.