使用 PHP 將數據放到服務器上(新的 DOMdocument 不起作用) (Use PHP to put data onto server ( new DOMdocument not working))


問題描述

使用 PHP 將數據放到服務器上(新的 DOMdocument 不起作用) (Use PHP to put data onto server ( new DOMdocument not working))

I've been trying to incorporate a log of usage on my website.  I'm using the following PHP code for it..

<?php
echo "Hello";
$named = new DOMDocument();
echo "is";
$named‑>loadHTMLFile("html/trial12.htm");
echo "anybody";
$fartele = $named‑>getElementById("art");
echo "home?";
$value = $fartele‑>textContent;
echo $value;
$ip = $_SERVER['REMOTE_ADDR'];
$file=fopen("logofusage.out","a+");
fwrite($file,$value);
fwrite($file,",");
fwrite($file,$ip);
fwrite($file,",");
$timevariable = date("l dS \of F Y h:i:s A")."\n";
fwrite($file,$timevariable);
fclose($file);
?>

The echo thing is for debugging. But I can seem to get the script to run on my university's webserver. If I use just some predefined value for "$value" variable, and comment out the top part, I can see that the logofusage file is being populated. But when I use the script as above, I can't get past the "Hello". So I figure the problem is on the "new DOMDocument " line. Can anyone tell me what it could be?

P.S. Just to clarify a bit more, I am using Javascript to accept an input from the user and saving it to a "div" element in the HTML file, and then accessing the text inside the "div" element. The server uses PHP Version 5.3.1 .  And my HTML document has a doctype HTML 4.01 Transitional Thanks for the help. :) Ajrocker

 So the university server does not have the DOMDocument extension. Guess that's that 

Is there any other way to pull data from the HTML file and post it onto the server without AJAX...

‑‑‑‑‑

參考解法

方法 1:

if you don't get past 

new DOMDocument();

then I guess this extension is not available.

B/c there is not much that could be wrong with your script up to this point.

Check the output of phpinfo() and/or get_loaded_extensions() to see which are available.

Also libxml is required to get DOMDocument do its job.

方法 2:

Check if your DOMDocument extension is enabled (using phpinfo() or cli).

(by ajrockerRaffaelRobert de W)

參考文件

  1. Use PHP to put data onto server ( new DOMdocument not working) (CC BY‑SA 3.0/4.0)

#domdocument #file-handling #PHP






相關問題

PHP/DOMDocument: unset() 不釋放資源 (PHP/DOMDocument: unset() does not release resources)

C++ Xerces Parser 加載 HTML 並蒐索 HTML 元素 (C++ Xerces Parser Load HTML and Search for HTML Elements)

Cách lấy tên thuộc tính kiểu bằng PHP xpath (How to get the style property name using PHP xpath)

DOMDocument:如何解析類似 bbcode 的標籤? (DOMDocument : how to parse a bbcode like tag?)

如何使用 DOMDocument 獲取此 html 中的 url (How to use DOMDocument to get url in this html)

DomDocument 未能為 RSS 提要添加“鏈接”元素 (DomDocument failing to add a "link" element for RSS feed)

如何防止將文檔類型添加到 HTML 中? (How to prevent the doctype from being added to the HTML?)

PHP DOM 文檔回顯問題 (PHP DOMdocument echoing problem)

使用 PHP 將數據放到服務器上(新的 DOMdocument 不起作用) (Use PHP to put data onto server ( new DOMdocument not working))

有沒有辦法構建類似於 DOMDocument 構建 HTML 文檔的 SQL 查詢? (Is there a way to build SQL queries similar to how DOMDocument builds HTML document?)

來自 URL 的 file_get_contents 僅適用於本地服務器 (file_get_contents from URL works on local server only)

使用多個 <table> 標記抓取 HTML 頁面並從特定的 <a> 標記後代中提取文本 (Scrape HTML page with multiple <table> tags and extract text from specific <a> tag descendants)







留言討論