How to automate FTP-ing file to another FTP account?

 We will be using shell script to automate the transfer between two FTP accounts. You’ll need shell access to the source FTP account. #!/bin/bash directory=”/home/raisya/public_html” filename=”test.txt” hostname=”ftp.destination.com” username=”dest” password=”qwerty” logfile=”ftpf.log” ftp -uni $hostname <>$logfile quote USER $username quote PASS $password lcd $directory put $filename quit EOF Explanation: directory=”/home/raisya/public_html” Assigning “/home/raisya/public_html” to directory. filename=”test.txt” Assigning “test.txt” […] Continue reading →

How to grab BCA USD buy/sell rate with cURL?

 This will grab current rate of USD rate from BCA using cURL. function delAttr($tagSource) { $stripAttrib = “‘ (style|class)=\”(.*?)\”‘i”; $tagSource = stripslashes($tagSource); $tagSource = preg_replace($stripAttrib, ”, $tagSource); return $tagSource; } function delTags($source) { $allowedTags=”; $source = strip_tags($source, $allowedTags); return preg_replace(‘/<(.*?)>/ie’, “‘<‘.delAttr(‘\\1′).’>'”, $source); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, “http://www.klikbca.com/individual/silver/ind/rates.html”); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); […] Continue reading →

PHP function to cut string into a specific length

 PHP function to cut string into a specific length. Very useful for “Read More” links. function wCut($str, $maxLength = 40) { $strToCount = html_entity_decode($str); if (strlen($strToCount) <= $maxLength) { return $str; } $s2 = substr($strToCount, 0, $maxLength – 3); $s2 .= “…”; return htmlentities($s2); } $str = ‘Lorem ipsum dolor sit amet, consectetur adipiscing elit. […] Continue reading →