Friday, September 17, 2010

format base strip sscanf php

function stripCurrency($input) {

$input = str_replace(",","",$input);
$input = str_replace("$","",$input);

return $input;
}

function stripRoadTax($input) {

$input = str_replace(",","",$input);
$input = str_replace("$","",$input);
list($val) = sscanf($input, "%d per year");

return $val;
}

function stripMileage($input) {

$input = str_replace(",","",$input);
list($val) = sscanf($input, "%d km");

return $val;
}

mysql php installation errors server 2008 zlib.dll

When IIS is complaining about a missing DLL file either a zlib.dll or oci.dll, chances are soemthing is wrong with the msi file, disable some of the extensions and try to install again, as long as php-cgi.exe runs properly, the program should work.

after ensuring that php works, follow the insturctions to edit the php.ini file to point to the correct fastcgi settings.
http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-7/

I installed PHP on C:\PHP and not within program files directory mainly because of the space.

lastly, take note of the appliaction pool, the manage pipeline mode should be integrated and the "enable 32 bit applications" setting should be set to true.

Wednesday, September 8, 2010

Performance xpath->query vs dom->getElementsByTagName

xpath works much faster, with speed of over 3 times faster compared to that of doing normal traversal using DOM.

// dom method
$xpath = new DOMXPath($dom);
$nodes = $dom->getElementsByTagName('td');
foreach($nodes as $node) {

if($node->nodeName == 'td'){

$inodes = $node->childNodes;

if ($node->getAttribute('class') == 'usedcar_InfoName usedcar_InfoName_padding') {
echo $node->nodeValue . "
";
}

if ($node->getAttribute('class') == 'usedcar_InfoContent usedcar_InfoContent_padding') {
echo @mb_convert_encoding(htmlspecialchars($node->nodeValue), 'utf-8') . "
";
}

foreach($inodes as $inode){

if($inode->nodeName == 'a' && $inode->getAttribute('class') == 'breadcrumb_link') {
echo $inode->nodeValue . "
";
}

if($inode->nodeName == 'td' && $inode->getAttribute('class') == 'usedcar_InfoName usedcar_InfoName_padding') {
echo $inode->nodeValue . "
";

}
}
}
}

// xpath method
$xpath = new DOMXPath($dom);
$title = $xpath->query("/html/title");
$elements = $xpath->query("//*[@class='usedcar_InfoName usedcar_InfoName_padding']"); // header
$elements2 = $xpath->query("//*[@class='usedcar_InfoContent usedcar_InfoContent_padding']"); // content

// dump all the header tag into an array
$headers = array();
if (!is_null($elements)) {
foreach ($elements as $element) {
$nodes = $element->childNodes;
foreach ($nodes as $node) {
array_push($headers, $node->nodeValue);
}
}
}

// dump all content tag into an array
$contents = array();
if (!is_null($elements2)) {
foreach ($elements2 as $element) {
$nodes = $element->childNodes;
$count =0;
foreach ($nodes as $node) {
if ($count == 0)
array_push($contents, $node->nodeValue);
$count++;
}
}
}

for($count=0; $count < sizeof($headers); $count++)
echo $headers[$count] . ": " . $contents[$count] . "
";