torvald_helmer Posted April 19, 2007 Share Posted April 19, 2007 Is there a way to print the html source code? $file = file_get_contents("text.html"); print_r($file); When I do this, it just shows the page as I would have seen it if I loaded the text.html in my browser. What I want is to print the source code, as this: <html> <body> texts and tags... </body> </html> Is there a way to do this?? I want this because I am making a script that reads text in xhtml-format and sending the text to a database. Instead of having pages with unstructured xhtml, I want to have it all in a database, structured form. So I need to now the tags, so I can get the text-content out of the tags and send it to databases. Link to comment https://forums.phpfreaks.com/topic/47743-print-html-source-code/ Share on other sites More sharing options...
kenrbnsn Posted April 19, 2007 Share Posted April 19, 2007 You need to use the function htmlentities() on each line when sending them to the browser. <?php $file = file("text.html"); foreach ($file as $line) echo nl2br(htmlentities($line,ENT_QUOTES))."\n"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/47743-print-html-source-code/#findComment-233191 Share on other sites More sharing options...
torvald_helmer Posted April 19, 2007 Author Share Posted April 19, 2007 Thanks! That worked like I wanted it. While I am at it, do you have some tips about how to extract text? In addition to html, head, body, meta-tags the html-file consist of a table, and each of there rows (<tr>) have some text I want to extract. E.g <tr><td class="field">Lecturer</td><td>Professor Robert Langdon<br/></td></tr> All rows has the same field class. When I see the first <td>, here with 'lecturer', I want to to get the content of the second <td>. The first td is the name of a coloum in my database, which will have the content of the second td. Link to comment https://forums.phpfreaks.com/topic/47743-print-html-source-code/#findComment-233202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.