function getLastOperation($html)
{
    $pos = 0;
    $doc = new DOMDocument();
    @$doc->loadHTML($html);
    $operations = "";
    foreach ($doc->getElementsByTagName('td') as $tag) {
        if (trim($tag->nodeValue) === "fin") {
            break;
        }
        if ($tag->getAttribute('id') === "fecha") {
            $operations[$pos]->date = cleanString($tag->nodeValue);
        } else {
            if ($tag->getAttribute('id') === "operacion") {
                $operations[$pos]->name = removeLastWord($tag->nodeValue);
            } else {
                if ($tag->getAttribute('id') === "importe") {
                    $operations[$pos]->price = cleanString($tag->nodeValue);
                } else {
                    if ($tag->getAttribute('id') === "horaOperacion") {
                        $operations[$pos]->hour = cleanString($tag->nodeValue);
                        $pos++;
                    }
                }
            }
        }
    }
    return $operations;
}
<?php

include 'testutils.php';
include '../htmlhelper.php';
$html_okwithoutops = file_get_contents('resources/response_okwithoutops.html');
$html_ok = file_get_contents('resources/response_ok.html');
$html_fail = file_get_contents('resources/response_fail.html');
echo "</br>getCurrentBalance</br>";
echo assertEquals(getCurrentBalance($html_okwithoutops), "0") . "</br>";
echo assertEquals(getCurrentBalance($html_ok), "34,56") . "</br>";
echo assertEquals(getCurrentBalance($html_fail), "") . "</br>";
echo "</br>getLastOperation</br>";
echo assertEquals(getLastOperation($html_okwithoutops), "") . "</br>";
echo "</br>Remove Last Operation</br>";
echo assertEquals(removeLastWord("hola"), "hola") . "</br>";
echo assertEquals(removeLastWord(" hola "), "hola") . "</br>";
echo assertEquals(removeLastWord("  hola "), "hola") . "</br>";
echo assertEquals(removeLastWord("   hola M"), "hola") . "</br>";
Пример #3
0
function appendPreviewArticles($article, $sizeLimit = 350)
{
    $id = $article["id"];
    $title = $article["title"];
    $date = $article["created"];
    $date = utf8_encode(strftime('%d %B %Y', article_time_given_date($article['created'])));
    $author = $article["author"];
    $content = $article["html"];
    $link = $article["slug"];
    $contentText = limitHTMLText($content, $sizeLimit);
    $contentText = closetags(removeLastWord($contentText) . " …");
    $contentText = removeStyleAttribute($contentText);
    echo '<a href="/posts/' . $link . '" class="hidden-link article-link">
                    <div class="inner">
                        <div class="date">' . $date . '</div>
                        <div class="title">' . $title . '</div>
                        ' . $contentText . '
                    </div>
                </a>';
}
Пример #4
0
 public static function generateQuery()
 {
     if (empty(self::$rawQuery)) {
         $result = "SELECT " . (count(self::$select) > 0 ? implode(",", self::$select) : "*") . PHP_EOL . "FROM " . self::$table . PHP_EOL . (!empty(self::$join) ? trim(removeLastWord(self::$join)) : "") . (!empty(self::$where) ? " WHERE " . self::$where : "") . self::$groupBy . self::$orderBy . self::$limit;
     } else {
         $result = self::$rawQuery;
     }
     return $result;
 }