楽天市場のAPIを使用して、ユーザの入力したキーワードにヒットする商品の一覧を表示し、
それぞれの商品のページへのリンクを作成したいのですが、
http://php.net/manual/ja/domelement.setattribute.php
を参考にコードを書いてみたところ、
PHP Fatal error: Class 'DOMDocument' not found in ...
とエラーが出てしまいます。
調べたところ、これはDOMがPHPに組み込まれていない事が原因のようで、
sudo権限がないと解決できないという事がわかりました。
使用しているサーバが研究室のサーバであるため、自分にはsudo権限がありません。
sudo権限を持つ人にインストールをお願いする以外に何か方法があれば、教えてください。
宜しくお願い致します。
###ソースコード(リンク先のコードのコピペです)
<?php //Store your html into $html variable. $html=" <html> <head> <title>Untitled Document</title> </head> <body> <a href='http://example.com'>Example</a><br> <a href='http://google.com'>Google</a><br> <a href='http://www.yahoo.com'>Yahoo</a><br> </body> </html>"; $dom = new DOMDocument(); $dom->loadHTML($html); //Evaluate Anchor tag in HTML $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); //remove and set target attribute $href->removeAttribute('target'); $href->setAttribute("target", "_blank"); $newURL=$url."/newurl"; //remove and set href attribute $href->removeAttribute('href'); $href->setAttribute("href", $newURL); } // save html $html=$dom->saveHTML(); echo $html; ?>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。