Symfony\Component\DomCrawler\Crawler::text PHP Method

text() public method

Returns the node value of the first node of the list.
public text ( ) : string
return string The node value
    public function text()
    {
        if (!$this->nodes) {
            throw new \InvalidArgumentException('The current node list is empty.');
        }
        return $this->getNode(0)->nodeValue;
    }

Usage Example

 public static function parse($contents, $id, $type)
 {
     $crawler = new Crawler();
     $crawler->addHTMLContent($contents, 'UTF-8');
     $rows = $crawler->filter('div[class="spaceit_pad"]');
     $title = preg_replace('/ (\\w+?) Details/', '$2', $crawler->filter('div[class="normal_header"]')->text());
     $result = array();
     if ($type === 'anime') {
         foreach ($rows as $historyItem) {
             $crawler = new Crawler($historyItem);
             $date = explode(' ', $crawler->text());
             $historyinfo['item'] = new Anime();
             $historyinfo['item']->setId((int) $id);
             $historyinfo['item']->setTitle($title);
             $historyinfo['item']->setWatchedEpisodes((int) $date[1]);
             $historyinfo['type'] = $type;
             $historyinfo['time_updated'] = Date::formatTime($date[4] . ' ' . $date[6]);
             $result[] = $historyinfo;
         }
     } else {
         foreach ($rows as $historyItem) {
             $crawler = new Crawler($historyItem);
             $date = explode(' ', $crawler->text());
             $historyinfo['item'] = new Manga();
             $historyinfo['item']->setId((int) $id);
             $historyinfo['item']->setTitle($title);
             $historyinfo['item']->setChaptersRead((int) $date[1]);
             $historyinfo['type'] = $type;
             $historyinfo['time_updated'] = Date::formatTime($date[4] . ' ' . $date[6]);
             $result[] = $historyinfo;
         }
     }
     return $result;
 }
All Usage Examples Of Symfony\Component\DomCrawler\Crawler::text