0

I want to know how i can find the DIV tag in a HTML page. This is because i want to replace the links inside that DIV with different links. I do not understand what exact code i require.

user1295105
  • 35
  • 1
  • 2
  • 7
  • @Blake it seems that he tried asking the same thing another time http://stackoverflow.com/questions/10215357/change-html-contents-using-php :) – mishu Apr 19 '12 at 15:16

1 Answers1

1

First, notice that PHP won't do anything client side. But you should already know it. you should use file_get_contents to read the webpage as a string (or what is provided by a library for html parsing).

There is already a question that explain how to parse html in any way: Robust and Mature HTML Parser for PHP

If it doesn't fit your needs, try searching it on google: php html parsing, I found some libraries

For example this library I've found allows you to find all tags: http://simplehtmldom.sourceforge.net/

Notice that this is not a great approach and I suggest you change your html page to be a PHP page, and insert some code in place of A tags. This will make everything easier.

Last thing, if the html page is static (it doesn't change), you can use easily line counting to get contents from X line to Y line, put your customized A-tags and then read from J to the end of file.

Good luck anyway.

Community
  • 1
  • 1
Francesco Belladonna
  • 11,361
  • 12
  • 77
  • 147