saturation
asked on
Use PHP parsing to write out contents between tags
I'm trying to "echo" the contents inside my "<span>" tag to the page using the getArticles function below. It doesn't seem to want to write it out. The function and only part of the HTML are below. What am I doing wrong?
// HTML
<span class='clr2 b'>My Test</span>
************************** ********** ********** ********** ******
// FUNCTION
function getArticles($page) {
global $articles;
$html = new simple_html_dom();
$html->load_file($page);
//echo $html;
$items = $html->find("span[class=cl r2 b]");
foreach($items as $post) {
# remember comments count as nodes
// outertext
// innertext
// plaintext
$articles[] = array($post->children(0)-> outertext) ;
}
foreach($articles as $item) {
echo $item[0];
}
}
************************** ********** ********** ***
// HTML
<span class='clr2 b'>My Test</span>
**************************
// FUNCTION
function getArticles($page) {
global $articles;
$html = new simple_html_dom();
$html->load_file($page);
//echo $html;
$items = $html->find("span[class=cl
foreach($items as $post) {
# remember comments count as nodes
// outertext
// innertext
// plaintext
$articles[] = array($post->children(0)->
}
foreach($articles as $item) {
echo $item[0];
}
}
**************************
ASKER
It's because I don't have direct access to the page, and I'm just trying to get used to handling a parser, so I don't have a choice--the data is already written out to the page.
What are you getting on the screen right now?
ASKER
Nothing....Here's the full code:
// TEST.HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<span class='clr2 b'>My Test</span>
</body>
</html>
// INDEX.HTML
include('simple_html_dom.p hp');
$articles = array();
getArticles('test.html');
// SIMPLE_HTML_DOM.PHP -- THIS PAGE DOES WORK, I DIDN'T INCLUDE ALL OF THE CODE. I
function getArticlesCars($page) {
global $articles;
$html = new simple_html_dom();
$html->load_file($page);
$items = $html->find("span[class=cl r2 b]");
foreach($items as $post) {
# remember comments count as nodes
// outertext
// innertext
// plaintext
$articles[] = array($post->children(0)-> outertext) ;
}
foreach($articles as $item) {
echo $item[0];
}
}
// TEST.HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<span class='clr2 b'>My Test</span>
</body>
</html>
// INDEX.HTML
include('simple_html_dom.p
$articles = array();
getArticles('test.html');
// SIMPLE_HTML_DOM.PHP -- THIS PAGE DOES WORK, I DIDN'T INCLUDE ALL OF THE CODE. I
function getArticlesCars($page) {
global $articles;
$html = new simple_html_dom();
$html->load_file($page);
$items = $html->find("span[class=cl
foreach($items as $post) {
# remember comments count as nodes
// outertext
// innertext
// plaintext
$articles[] = array($post->children(0)->
}
foreach($articles as $item) {
echo $item[0];
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window