getattribute and tag value using dom - php

There are similar threads available. I look on them and tried to get. Here i can get the address value but phone number and image url is not comming.
Where I make mistake here?
function getData($url){
$containers1 = $html->find('div.mapbox div.mapbox-text strong.street-address address');
foreach($containers1 as $container)
{
$comments = $container->find('span');
$item = new stdClass();
foreach($comments as $comment)
{
$address.= $comment->plaintext; //append the content of each span
}
echo $address; // this gives correct result
}
$containers2 = $html->find('div.mapbox div.mapbox-text span.biz-phone');
$phone = $containers2->innertext;
echo "<br/>".$phone."<br/>"; // no result
$Imgcontainers = $html->find('div.js-photo photo photo-1 div.showcase-photo-box img');
echo $Imgcontainers->getAttribute('src'); // Fatal error: Call to a member function getAttribute() on a non-object
}
}
$url = 'http://www.yelp.com/biz/locanda-san-francisco?start=40';
$root = getData($url);
UPDATE
I added this:
$Imgcontainers = $html->find('div.photo-1 img');
foreach($Imgcontainers as $cont){
$img[] = $cont->getAttribute('src');
}
echo $img[0];
http://s3-media3.ak.yelpcdn.com/bphoto/Pf2RTD8pNdy-oUnp-57m4Q/ls.jpghttp://s3-media3.ak.yelpcdn.com/bphoto/Pf2RTD8pNdy-oUnp-57m4Q/ls.jpg
Same url twice? why twice though we echo only 0th array value?

Use this code
foreach($containers1 as $container)
{
$comments = $container->find('span');
$item = new stdClass();
foreach($comments as $comment)
{
$address.= $comment->plaintext; //append the content of each span
}
echo $address; // this gives correct result
}
$containers2 = $html->find('div.mapbox div.mapbox-text span.biz-phone');
foreach($containers2 as $contact){
$phone = $contact->plaintext;
}
echo "<br/>".$phone."<br/>"; // no result
$Imgcontainers = $html->find('div.photo-1 img');
foreach($Imgcontainers as $cont){
echo $cont->getAttribute('src');
}

Related

Storing array in sessions

I am trying to store some data as an array in the session but the function does not seem to be working.it does not throw any error but every time i add data to it, it just overwrites the previous data. I am using yii and here is the action
public function actionStoreProducts($name)
{
$name=trim(strip_tags($name));
if(!empty($name))
{
if(!isset(Yii::app()->session['_products']))
{
Yii::app()->session['_products']=array($name);
echo 'added';
}
else
{
$myProducts = Yii::app()->session['_products'];
$myProducts[] = $name;
Yii::app()->session['products'] = $myProducts;
echo 'added';
}
}
Can anyone suggest me how can i achieve the desired result?
Please correct your code like this .
public function actionStoreProducts($name) {
$name = trim(strip_tags($name));
if (!empty($name)) {
if (!isset(Yii::app()->session['_products'])) {
Yii::app()->session['_products'] = array($name);
echo 'added';
} else {
$myProducts = Yii::app()->session['_products'];
$myProducts[] = $name;
Yii::app()->session['_products'] = $myProducts;
echo print_r(Yii::app()->session['_products']);
echo 'added';
}
}
}
session property read-only
i think the correct aproach is :
function actionStoreProducts($name) {
$session = new CHttpSession; //add this line
$session->open(); //add this line
$name = trim(strip_tags($name));
if (!empty($name)) {
if (!isset(Yii::app()->session['_products'])) {
$session->add('_products', array($name)); //replace this line
echo 'added';
} else {
$myProducts = Yii::app()->session['_products'];
$myProducts[] = $name;
$session->add('_products', $myProducts); //replace this line
echo 'added';
}
}
}
first get an variable into $session['somevalue'] ,then sore in array variable, Use Like IT:-
$session = new CHttpSession;
$session->open();
$myval = $session['somevalue'];
$myval[] = $_POST['level'];
$session['somevalue'] = $myval;

RSS Parser to include Categories

I recently inherited a RSS/XML parser, and while it seems to work really good, I'm finding some things are missing.
For instance, pulling in a RSS feed from a blog. It's missing all the categories in the items. It shows as each item having only one category when in reality it should show as having a multitude of categories.
Link to Demo: http://dev.o7t.in/rss/
Link to Actual Feed: http://o7thblog.com/feed/
You can see how the first item in the feed itself has 8 total categories in the first item. (may need to view source)
However, in the Demo you can see that it only shows 1 category
Here is my entire code for the class:
<?php
class o7thRssFeedPuller{
public $FeedUrl = ''; // URL of the feed to pull in
public $ReturnJson = false; // Return the array as a JSON encoded string instead?
public $MaxItems = 0; // 0 = unlimited (except by feed), only applicable to GetItems
// Internal holders
private $document;
private $channel;
private $items;
// Get the full RSS feed
public function GetRSS($includeAttributes = false) {
// Pull in our feed
$this->loadParser(file_get_contents($this->FeedUrl, false, $this->randomContext()));
if($includeAttributes) {
// only if we are including attributes
return ($this->ReturnJson) ? json_encode($this->document) : $this->document;
}
// Return either an array or a json encoded string
return ($this->ReturnJson) ? json_encode($this->valueReturner()) : $this->valueReturner();
}
// Get the channel data
public function GetChannel($includeAttributes = false) {
// Pull in our feed
$this->loadParser(file_get_contents($this->FeedUrl, false, $this->randomContext()));
if($includeAttributes) {
// only if we are including attributes
return ($this->ReturnJson) ? json_encode($this->channel) : $this->channel;
}
// Return either an array or a json encoded string
return ($this->ReturnJson) ? json_encode($this->valueReturner($this->channel)) : $this->valueReturner($this->channel);
}
// Get the items
public function GetItems($includeAttributes=false) {
// Pull in our feed
$this->loadParser(file_get_contents($this->FeedUrl, false, $this->randomContext()));
if($includeAttributes) {
// only if we are including attributes
$arr = ($this->MaxItems == 0) ? $this->items : array_slice($this->items, 0, $this->MaxItems);
return ($this->ReturnJson) ? json_encode($arr) : $arr;
}
// Return either an array or a json encoded string
$arr = ($this->MaxItems == 0) ? $this->valueReturner($this->items) : array_slice($this->valueReturner($this->items), 0, $this->MaxItems);
return ($this->ReturnJson) ? json_encode($arr) : $arr;
}
// -------------------------------------------------------------------------------------------------
// Internal Methods
private function loadParser($rss=false) {
if($rss) {
$this->document = array();
$this->channel = array();
$this->items = array();
$DOMDocument = new DOMDocument;
$DOMDocument->strictErrorChecking = false;
$DOMDocument->loadXML($rss);
$this->document = $this->extractDOM($DOMDocument->childNodes);
}
}
private function valueReturner($valueBlock=false) {
if(!$valueBlock) {
$valueBlock = $this->document;
}
foreach($valueBlock as $valueName => $values) {
if(isset($values['value'])) {
$values = $values['value'];
}
if(is_array($values)) {
$valueBlock[$valueName] = $this->valueReturner($values);
} else {
$valueBlock[$valueName] = $values;
}
}
return $valueBlock;
}
private function extractDOM($nodeList,$parentNodeName=false) {
$itemCounter = 0;
foreach($nodeList as $values) {
if(substr($values->nodeName,0,1) != '#') {
if($values->nodeName == 'item') {
$nodeName = $values->nodeName.':'.$itemCounter;
$itemCounter++;
} else {
$nodeName = $values->nodeName;
}
$tempNode[$nodeName] = array();
if($values->attributes) {
for($i=0;$values->attributes->item($i);$i++) {
$tempNode[$nodeName]['properties'][$values->attributes->item($i)->nodeName] = $values->attributes->item($i)->nodeValue;
}
}
if(!$values->firstChild) {
$tempNode[$nodeName]['value'] = $values->textContent;
} else {
$tempNode[$nodeName]['value'] = $this->extractDOM($values->childNodes, $values->nodeName);
}
if(in_array($parentNodeName, array('channel','rdf:RDF'))) {
if($values->nodeName == 'item') {
$this->items[] = $tempNode[$nodeName]['value'];
} elseif(!in_array($values->nodeName, array('rss','channel'))) {
$this->channel[$values->nodeName] = $tempNode[$nodeName];
}
}
} elseif(substr($values->nodeName,1) == 'text') {
$tempValue = trim(preg_replace('/\s\s+/',' ',str_replace("\n",' ', $values->textContent)));
if($tempValue) {
$tempNode = $tempValue;
}
} elseif(substr($values->nodeName,1) == 'cdata-section'){
$tempNode = $values->textContent;
}
}
return (!isset($tempNode)) ? null : $tempNode;
}
// Load in a random header to pass
private function randomContext() {
$headerstrings = array();
$headerstrings['User-Agent'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.'.rand(0,2).'; en-US; rv:1.'.rand(2,9).'.'.rand(0,4).'.'.rand(1,9).') Gecko/2007'.rand(10,12).rand(10,30).' Firefox/2.0.'.rand(0,1).'.'.rand(1,9);
$headerstrings['Accept-Charset'] = rand(0,1) ? 'en-gb,en;q=0.'.rand(3,8) : 'en-us,en;q=0.'.rand(3,8);
$headerstrings['Accept-Language'] = 'en-us,en;q=0.'.rand(4,6);
$setHeaders = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'."\r\n".
'Accept-Charset: '.$headerstrings['Accept-Charset']."\r\n".
'Accept-Language: '.$headerstrings['Accept-Language']."\r\n".
'User-Agent: '.$headerstrings['User-Agent']."\r\n";
$contextOptions = array(
'http'=>array(
'method'=>"GET",
'header'=>$setHeaders
)
);
return stream_context_create($contextOptions);
}
}
?>
And for the demo page:
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/rss/o7th.rss.feed.puller.php');
$fp = new o7thRssFeedPuller();
$fp->FeedUrl = 'http://o7thblog.com/feed';
$fp->MaxItems = 2;
echo '<table width="100%" cellpadding="0" cellspacing="0">';
echo ' <tr>';
echo ' <td>';
echo ' <textarea cols="120" rows="30">';
print_r($fp->GetItems());
echo ' </textarea>';
echo ' </td>';
echo ' </tr>';
echo '</table>';
?>
So, I assume that the issue lies somewhere in either the valueReturner method or the extractDOM method, but I am just not sure where, nor what I can do to get all the categories in the returned array.
Can you help?
I would suggest using SimpleXML to parse the feed.
Here is how you can do it:
$feed_url = 'http://o7thblog.com/feed/';
$feed = simplexml_load_file($feed_url, null, LIBXML_NOCDATA);
$channel = $feed->channel;
echo "<h1>{$channel->title}</h1>\n";
echo "{$channel->description}\n";
echo "<dl>\n";
foreach ($channel->item as $item) {
echo "<dt>{$item->title}</dt>\n"
. "<dd style=\"margin-bottom: 30px;\"><div style=\"font-size: small;\">{$item->pubDate}</div>\n"
. "<div>{$item->description}</div>\n"
. "Categories: <strong>".implode('</strong>, <strong>', (array) $item->category) . "</strong>\n</dd>";
}
echo "</dl>\n";
Above shows you all categories.
You have written a custom parser for what you can do simply with one line of code!
$feed = (array) simplexml_load_file('http://o7thblog.com/feed/', null, LIBXML_NOCDATA);

How to convert PHP to XML output

I have a php code. this code outputs an HTML. I need to modify this code to output an XML.
ANy ideas as to how shall I go about doing this. Is there any XML library available that directly does the job or do i have to manually create each node.?
My php code is:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
a {text-decoration:none; color:black;}
</style>
</head>
<body>
<?php
$a=$_POST["title"];
$b=$_POST["name"];
$c="http://www.imdb.com/search/title?title=".urlencode($a)."&title_type=".urlencode($b);
$d=file_get_contents($c);
preg_match_all('/<div id="main">\n(No results.)/', $d,$nore);
preg_match_all('#<img src="(.*)"#Us', $d, $img);//image
preg_match_all('/<a\s*href="\/title\/tt[0-9]*\/">((?:[a-z]*(?:&*[.]*)?\s*-*[a-z]*[0-9]*[^<])+)/i',$d,$tit); //title
preg_match_all('/<span\sclass="year_type">\s*\(([\d]*)/',$d,$ye); //movie year working fine
preg_match_all('#<span class="credit">\n Dir: (.*)\n(?: With:)?#Us',$d,$dir); //director
preg_match_all('/<span class="rating-rating"><span class="value">([\w]*.[\w]*)/i',$d,$rat); //rating
preg_match_all('/<a\shref="(\/title\/tt[0-9]*\/)"\s*[title]+/i',$d,$lin); //link
for($i=0;$i<5;$i++)
{
if (#$rat[1][$i]=="-")
$rat[1][$i]="N/A";
}
for($i=0;$i<5;$i++)
{
if(#$dir[1][$i]=="")
$dir[1][$i]="N/A";
}
if(count($tit[1])>5)
$cnt=5;
else
$cnt=count($tit[1]);
echo"<center><b>Search Result</b></center>";
echo "<br/>";
echo "<center><b>\"$a\"of type\"$b\":</b></center>";
echo"<br/>";
if(#$nore[1][0]=="No results.")
echo "<center><b>No movies found!</b></center>";
else
{
echo "<center><table border=1><tr><td><center>Image</center></td><td><center>Title</center></td><td><center>Year</center></td><td><center>Director</center></td><td><center>Rating(10)</center></td><td><center>Link to Movie</center></td></tr>";
for($j=0;$j<$cnt;$j++)
{
echo "<tr>";
echo "<td>".#$img[0][$j+2]."</td>";
echo "<td><center>".#$tit[1][$j]."</center></td>";
echo "<td><center>".#$ye[1][$j]."</center></td>";
echo "<td><center>".#$dir[1][$j]."</center></td>";
echo "<td><center>".#$rat[1][$j]."</center></td>";
echo '<td><center><a style="text-decoration:underline; color:blue;" href="http://www.imdb.com'.#$lin[1][$j].'">Details</a></center></td>';
echo "</tr>";
}
echo "</table></center>";
}
?>
</body>
</html>
Expected XML output:
<result cover="http://ia.mediaimdb.com/images
/M/MV5BMjMyOTM4MDMxNV5BMl5BanBnXkFtZTcwNjIyNzExOA##._V1._SX54_
CR0,0,54,74_.jpg" title="The Amazing Spider-Man(2012)"year="2012"
director="Marc Webb" rating="7.5"
details="http://www.imdb.com/title/tt0948470"/>
<result cover="http://ia.mediaimdb.
com/images/M/MV5BMzk3MTE5MDU5NV5BMl5BanBnXkFtZTYwMjY3NTY3._V1._SX54_CR0,
0,54,74_.jpg" title="Spider-Man(2002)" year="2002"director="Sam Raimi"
rating="7.3" details="http://www.imdb.com/title/tt0145487"/>
<result cover="http://ia.mediaimdb.
com/images/M/MV5BODUwMDc5Mzc5M15BMl5BanBnXkFtZTcwNDgzOTY0MQ##._V1._SX54_
CR0,0,54,74_.jpg" title="Spider-Man 3 (2007)" year="2007" director="Sam
Raimi" rating="6.3" details="http://www.imdb.com/title/tt0413300"/>
<result cover="http://i.mediaimdb.
com/images/SF1f0a42ee1aa08d477a576fbbf7562eed/realm/feature.gif" title="
The Amazing Spider-Man 2 (2014)" year="2014" director="Sam Raimi"
rating="6.3" details="http://www.imdb.com/title/tt1872181"/>
<result cover="http://ia.mediaimdb.
com/images/M/MV5BMjE1ODcyODYxMl5BMl5BanBnXkFtZTcwNjA1NDE3MQ##._V1._SX54_
CR0,0,54,74_.jpg" title="Spider-Man 2 (2004)" year="2004" director="Sam
Raimi" rating="7.5" details="http://www.imdb.com/title/tt0316654"/>
</results>
First thing, you're parsing your html result with regex which is inefficient, unnecessary, and... well, you're answering to the cthulhu call!
Second, parsing IMDB HTML to retrieve results, although valid, might be unnecessary. There are some neat 3rd party APIs that do the job for you, like http://imdbapi.org
If you don't want to use any 3rd party API though, IMHO, you should, instead, parse the HTML using a DOM parser/manipulator, like DOMDocument, for instance, which is safer, better and, at the same time, can solve your HTML to XML problem.
Here's the bit you asked (build XML and HTML from results):
function resultsToHTML($results)
{
$doc = new DOMDocumet();
$table = $doc->createElement('table');
foreach ($results as $r) {
$row = $doc->createElement('tr');
$doc->appendChild($row);
$title = $doc->createElement('td', $r['title']);
$row->appendChild($title);
$year = $doc->createElement('td', $r['year']);
$row->appendChild($year);
$rating = $doc->createElement('td', $r['rating']);
$row->appendChild($rating);
$imgTD = $doc->createElement('td');
//Creating a img tag (use only on)
$img = $doc->createElement('img');
$img->setAttribute('src', $r['img_src']);
$imgTD->appendChild($img);
$row->appendChild($imgTD);
$imgTD = $doc->createElement('td');
//Importing directly from the old document
$fauxDoc = new DOMDocument();
$fauxDoc->loadXML($r['img']);
$img = $fauxDoc->getElementsByTagName('img')->index(0);
$importedImg = $doc->importNode('$img', true);
$imgTD->appendChild($importedImg);
$row->appendChild($imgTD);
}
return $doc;
}
function resultsToXML($results)
{
$doc = new DOMDocumet();
$root = $doc->createElement('results');
foreach ($results as $r) {
$element = $root->createElement('result');
$element->setAttribute('cover', $r['img_src']);
$element->setAttribute('title', $r['title']);
$element->setAttribute('year', $r['year']);
$element->setAttribute('rating', $r['rating']);
$root->appendChild($element);
}
$doc->appendChild($root);
return $doc;
}
to print them you just need to
$xml = resultsToXML($results);
print $xml->saveXML();
Same thing with html
Here's a refactor of your code with DOMDocument, based on your post:
<?php
//Mock IMDB Link
$a = 'The Amazing Spider-Man';
$b = 'title';
$c = "http://www.imdb.com/search/title?title=".urlencode($a)."&title_type=".urlencode($b);
// HTML might be malformed so we want DOMDocument to be quiet
libxml_use_internal_errors(true);
//Initialize DOMDocument parser
$doc = new DOMDocument();
//Load previously downloaded document
$doc->loadHTMLFile($c);
//initialize array to store results
$results = array();
// get table of results and extract a list of rows
$listOfTables = $doc->getElementsByTagName('table');
$rows = getResultRows($listOfTables);
$i = 0;
//loop through all rows to retrieve information
foreach ($rows as $row) {
if ($title = getTitle($row)) {
$results[$i]['title'] = $title;
}
if (!is_null($year = getYear($row)) && $year) {
$results[$i]['year'] = $year;
}
if (!is_null($rating = getRating($row)) && $rating) {
$results[$i]['rating'] = $rating;
}
if ($img = getImage($row)) {
$results[$i]['img'] = $img;
}
if ($src = getImageSrc($row)) {
$results[$i]['img_src'] = $src;
}
++$i;
}
//the first result can be a false positive due to the
// results' table header, so we remove it
if (isset($results[0])) {
array_shift($results);
}
FUNCTIONS
function getResultRows($listOfTables)
{
foreach ($listOfTables as $table) {
if ($table->getAttribute('class') === 'results') {
return $table->getElementsByTagName('tr');
}
}
}
function getImageSrc($row)
{
$img = $row->getElementsByTagName('img')->item(0);
if (!is_null($img)) {
return $img->getAttribute('src');
} else {
return false;
}
}
function getImage($row, $doc)
{
$img = $row->getElementsByTagName('img')->item(0);
if (!is_null($img)) {
return $doc->saveHTML($img);
} else {
return false;
}
}
function getTitle($row)
{
$tdInfo = getTDInfo($row->getElementsByTagName('td'));
if (!is_null($tdInfo) && !is_null($as = $tdInfo->getElementsByTagName('a'))) {
return $as->item(0)->nodeValue;
} else {
return false;
}
}
function getYear($row)
{
$tdInfo = getTDInfo($row->getElementsByTagName('td'));
if (!is_null($tdInfo) && !is_null($spans = $tdInfo->getElementsByTagName('span'))) {
foreach ($spans as $span) {
if ($span->getAttribute('class') === 'year_type') {
return str_replace(')', '', str_replace('(', '', $span->nodeValue));
}
}
}
}
function getRating($row)
{
$tdInfo = getTDInfo($row->getElementsByTagName('td'));
if (!is_null($tdInfo) && !is_null($spans = $tdInfo->getElementsByTagName('span'))) {
foreach ($spans as $span) {
if ($span->getAttribute('class') === 'rating-rating') {
return $span->nodeValue;
}
}
}
}
function getTDInfo($tds)
{
foreach ($tds as $td) {
if ($td->getAttribute('class') == 'title') {
return $td;
}
}
}

Using Simple Html Dom to remove some elements

This is the page I'm trying to parse using Simple Html Dom. I've gotten 90% of the functionality done, but since I'm new to the library I'm not quite sure to do this.
I want to scrape the text of each news item, but since the text is inside the <p>element, using something like ->innertext bring everything inside, including the link.
Here's what I've tried:
<h1>Scraper Noticias</h1>
<?php
include('simple_html_dom.php');
class News {
var $image;
var $fechanoticia;
var $title;
var $description;
var $sourceurl;
function get_image( ) {
return $this->image;
}
function set_image ($new_image) {
$this->image = $new_image;
}
function get_fechanoticia( ) {
return $this->fechanoticia;
}
function set_fechanoticia ($new_fechanoticia) {
$this->fechanoticia = $new_fechanoticia;
}
function get_title( ) {
return $this->title;
}
function set_title ($new_title) {
$this->title = $new_title;
}
function get_description( ) {
return $this->description;
}
function set_description ($new_description) {
$this->description = $new_description;
}
function get_sourceurl( ) {
return $this->sourceurl;
}
function set_sourceurl ($new_sourceurl) {
$this->sourceurl = $new_sourceurl;
}
}
// Create DOM from URL or file
$html = file_get_html('http://www.uvm.cl/noticias_mas.shtml');
$parsedNews = array();
// Find all news items.
foreach($html->find('#cont2 p') as $element) {
$newItem = new News;
// Parse the news item's thumbnail image.
foreach ($element->find('img') as $image) {
$newItem->set_image($image->src);
//echo $newItem->get_image() . "<br />";
}
// Parse the news item's post date.
foreach ($element->find('span.fechanoticia') as $fecha) {
$newItem->set_fechanoticia($fecha->innertext);
//echo $newItem->get_fechanoticia() . "<br />";
}
// Parse the news item's title.
foreach ($element->find('a') as $title) {
$newItem->set_title($title->innertext);
//echo $newItem->get_title() . "<br />";
}
// Parse the news item's source URL link.
foreach ($element->find('a') as $sourceurl) {
$newItem->set_sourceurl("http://www.uvm.cl/" . $sourceurl->href);
}
// Parse the news items' description text.
echo $link; //This is the entire <p> tag. How can I get just the text. Not the link?
}
?>
Here's a solution I found. Although if I can improve the code, it would be appreciated.
<h1>Scraper Noticias</h1>
<?php
include('simple_html_dom.php');
class News {
var $image;
var $fechanoticia;
var $title;
var $description;
var $sourceurl;
function get_image( ) {
return $this->image;
}
function set_image ($new_image) {
$this->image = $new_image;
}
function get_fechanoticia( ) {
return $this->fechanoticia;
}
function set_fechanoticia ($new_fechanoticia) {
$this->fechanoticia = $new_fechanoticia;
}
function get_title( ) {
return $this->title;
}
function set_title ($new_title) {
$this->title = $new_title;
}
function get_description( ) {
return $this->description;
}
function set_description ($new_description) {
$this->description = $new_description;
}
function get_sourceurl( ) {
return $this->sourceurl;
}
function set_sourceurl ($new_sourceurl) {
$this->sourceurl = $new_sourceurl;
}
}
// Create DOM from URL or file
$html = file_get_html('http://www.uvm.cl/noticias_mas.shtml');
$parsedNews = array();
// Find all news items.
foreach($html->find('#cont2 p') as $element) {
$newItem = new News;
// Parse the news item's thumbnail image.
foreach ($element->find('img') as $image) {
$newItem->set_image($image->src);
//echo $newItem->get_image() . "<br />";
}
// Parse the news item's post date.
foreach ($element->find('span.fechanoticia') as $fecha) {
$newItem->set_fechanoticia($fecha->innertext);
//echo $newItem->get_fechanoticia() . "<br />";
}
// Parse the news item's title.
foreach ($element->find('a') as $title) {
$newItem->set_title($title->innertext);
//echo $newItem->get_title() . "<br />";
}
// Parse the news item's source URL link.
foreach ($element->find('a') as $sourceurl) {
$newItem->set_sourceurl("http://www.uvm.cl/" . $sourceurl->href);
}
// Parse the news items' description text.
foreach ($element->find('a') as $link) {
$link->outertext = '';
}
foreach ($element->find('span') as $link) {
$link->outertext = '';
}
foreach ($element->find('img') as $link) {
$link->outertext = '';
}
echo $element->innertext;
}
?>
Use the innertext instead of outertext
foreach ($element->find('a') as $sourceurl) {
echo $sourceurl->innertext . "<br />";
}

how to test if form is post or get?

how will i do this? i have the code:
public function executeListmatches(sfWebRequest $request)
{
$form_values = $request->getParameter('match_form', array());
if (isset($HTTP_POST_VARS))
{
$gender_id = $form_values['gender_id2'];
$age1 = $form_values['age1'];
$age2 = $form_values['age2'];
$province_id = $form_values['id'];
}
else
{
echo $gender_id = $request->getParameter('gender2');
echo $age1 = $request->getParameter('age1');
echo $age2 = $request->getParameter('age2');
echo $province_id = $request->getParameter('id');
}
$this->pager = $this->setupPager($gender_id,$age1,$age2,$province_id);
return sfView::SUCCESS;
}
but the line if (isset($HTTP_POST_VARS)) is not correct
thank you
You can check the method with sfWebRequest::isMethod($name);.
So use: if ($request->isMethod('POST')).
HTTP_POST_VARS & HTTP_GET_VARS are both deprecated. Your first condition is usisng POST data

Categories