Code Snippet

Get title from url

$href = 'http://www.japantimes.co.jp/';
$dom = new DOMDocument();
$file = file_get_contents($href); //read url into string
$dom->loadHTML($file); //load HTML
$xpath = new DOMXPath($dom);  
$titleNode = $xpath->query('//title');
var_dump($titleNode->item(0));

Get all link from url

$allLink = $dom->getElementsByTagName('a');
foreach($allLink as $link){
    echo $link->getAttribute('href')
}

Sử dụng toán tử !!

function Account(cash) {  
    this.cash = cash;
    this.hasMoney = !!cash;
}
var account = new Account(100.50);  
console.log(account.cash); // 100.50  
console.log(account.hasMoney); // true
var emptyAccount = new Account(0);  
console.log(emptyAccount.cash); // 0  
console.log(emptyAccount.hasMoney); // false