Page 1 of 1

Links swap

Posted: Mon Jul 12, 2010 8:00 am
by xionhack
Hello. I have a project that is a little bit complicated for me. I want to give the source of an html site as a string, check that string and save all the links in "href" to a database, then replace those links with the id that the database would give. For example:

Code: Select all

<html>
<body>
Hello, my name is <a href="http://www.link1.com">Xion</a>, and I'm trying to program in <a id="link" href="http://www.php.net">PHP</a>
</body>
</html>

What it would do is to save those two links in a database, into something like

Code: Select all

+------------------+------------------------------+
| Link_id          | LINK                         |
+------------------+------------------------------+
| 1                | http://www.link1.com         |
+------------------+------------------------------+
| 2                | http://www.php.net           |
+------------------+------------------------------+

And then swap the site with:

Code: Select all

<html>
<body>
Hello, my name is <a href="1">Xion</a>, and I'm trying to program in <a id="link" href="2">PHP</a>
</body>
</html>

IM STUCK!!! Can anybody help me? Thanks!

Re: Links swap

Posted: Mon Jul 12, 2010 8:48 am
by patel.manjeet
Hi...

very intesting job...

for this you need to Parsing html string and find all a tag with href att....

u can parse it using PHP DOM other any HTML Parsing i.e class get from google.

i find on HTML Parse class with document http://net.tutsplus.com/tutorials/php/h ... m-library/

u can ask any time if req. more help

Re: Links swap

Posted: Mon Jul 19, 2010 11:03 pm
by xionhack
Hey! I was trying that library. It looks very useful, the only problem, when I use the "a" tag, it gives me all the links, including the ones that are for the css or the js files. I only want the links with href, I asked the creator of it, but he didnt respond, do u have any idea on how to do it? thanks!