initial commit master
initial commit

file:b/sms.php (new)
--- /dev/null
+++ b/sms.php
@@ -1,1 +1,65 @@
+<?php
 
+/**
+ * @author		Razvan Stanga <git@razvi.ro>
+ */
+
+namespace donatiero;
+
+class sms {
+		private $originalHtml;
+		private $processedHtml;
+		private $regEx = "|<span style=\"color\: \#e30613\; font-size\: 24pt\;\"\>([a-z0-9\.]+)\<\/span\>|isU";
+		private $userAgent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31';
+
+		public function fetch($url)
+		{
+				if ( filter_var($url, FILTER_VALIDATE_URL) === false ) {
+						throw new \Exception ("invalid URL given");
+				}
+				$cookie = tmpfile();
+				$ch = curl_init($url);
+				$options = array(
+					CURLOPT_CONNECTTIMEOUT => 20 ,
+					CURLOPT_USERAGENT => $this->userAgent,
+					CURLOPT_AUTOREFERER => true,
+					CURLOPT_FOLLOWLOCATION => true,
+					CURLOPT_RETURNTRANSFER => true,
+					CURLOPT_COOKIEFILE => $cookie,
+					CURLOPT_COOKIEJAR => $cookie ,
+					CURLOPT_SSL_VERIFYPEER => 0 ,
+					CURLOPT_SSL_VERIFYHOST => 0
+				);
+				curl_setopt_array ($ch, $options);
+				$this->originalHtml = curl_exec ($ch);
+				curl_close ($ch);
+
+				return $this->match ();
+		}
+
+		private function processHtmlForRegx()
+		{
+				$this->processedHtml = preg_replace ("/([ ]+)/i", " ", $this->originalHtml);
+				$this->processedHtml = preg_replace ("/\r\n/i", "", $this->processedHtml);
+				$this->processedHtml = preg_replace ("/\n/i", "", $this->processedHtml);
+				$this->processedHtml = preg_replace ("/\r/i", "", $this->processedHtml);
+				$this->processedHtml = preg_replace ("/\t/i", " ", $this->processedHtml);
+				$this->processedHtml = preg_replace ("/([ ]+)/i", " ", $this->processedHtml);
+		}
+
+		private function match()
+		{
+			$this->processHtmlForRegx ();
+			preg_match ($this->regEx, $this->processedHtml, $match);
+			if ( count ($match) == 0 ) {
+				throw new \Exception ("regEx ".$this->regEx." result empty");
+			}
+			return $match;
+		}
+}
+
+$sms = new \donatiero\sms;
+$smss = $sms->fetch ("http://donatie.ro/index.php/doneaza-prin-sms/alege-organizatia/asociatia-m-a-m-e-raluca-tonciu");
+echo "var sms = '".$smss[1]."';";
+
+?>

comments