Alex Rivera | Logout

how to extract links and titles from a .html page?

Asked 2010-12-12T18:35:58.530
43

for my website, i'd like to add a new functionality.

I would like user to be able to upload his bookmarks backup file (from any browser if possible) so I can upload it to their profile and they don't have to insert all of them manually...

the only part i'm missing to do this it's the part of extracting title and URL from the uploaded file.. can anyone give a clue where to start or where to read?

used search option and (How to extract data from a raw HTML file?) this is the most related question for mine and it doesn't talk about it..

I really don't mind if its using jquery or php

Thank you very much.

Edit
Report

1 Answer

6

Assuming the stored links are in a html file the best solution is probably to use a html parser such as PHP Simple HTML DOM Parser (never tried it myself). (The other option is to search using basic string search or regexp, and you should probably never use regexp to parse html).

After reading the html file using the parser use it's functions to find the a tags:

from the tutorial:

// Find all links
foreach($html->find('a') as $element)
       echo $element->href . '<br>'; 
answered 2010-12-12T18:53:17.523

Your Answer