When ever I tried to insert text from the clipboard to vim it did either not work at all or the lines were inserted like a tree, each line more indented.
Archive for category php
Installing or updating a global installed composer can be a PITA if you don’t want to rely on the Linux distro
An easy way is:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/bin --filename=composer
mysql split string by comma and count
SELECT (LENGTH(`table`.`fieldname`) - LENGTH( REPLACE( `table`.`fieldname` , ',', '' ) ) + 1) AS `number` FROM `table` WHERE TRIM( IFNULL( `table`.`fieldname` , '' ) ) > ''
PHP sort array by key
Jan 27
Sorting an array by Key.
<?php /* Array ( [0] => Array ( [hashtag] => a7e87329b5eab8578f4f1098a152d6f4 [title] => Flower [order] => 3 ) [1] => Array ( [hashtag] => b24ce0cd392a5b0b8dedc66c25213594 [title] => Free [order] => 2 ) [2] => Array ( [hashtag] => e7d31fc0602fb2ede144d18cdffd816b [title] => Ready [order] => 1 ) ) */ function aasort (&$array, $key) { $sorter = array(); $ret = array(); reset($array); foreach ($array as $ii => $va) { $sorter[$ii] = $va[$key]; } asort($sorter); foreach ($sorter as $ii => $va) { $ret[$ii] = $array[$ii]; } $array = $ret; } aasort($your_array,"order"); ?>
MySQL not in other table
Jul 18
SELECT *
FROM `a`
WHERE NOT EXISTS
(SELECT *
FROM `b`
WHERE `b`.`id` = `a`.`id`)
__toString() must not throw an exception.
If you an exception handler even that seems fail (in itself) with __toString() must not throw an exception. There is no nice safe way to handle it. The easiest solution is to catch that error as well. It might seems to be odd, but on the other hand the exception hanler shall not fail ;)
/** * String representation of this object * @return string */ public function __toString() { try { return (string) $this->name; } catch (Exception $exception) { return ''; } }
Very simple
<?php function is_ios(){ if (stripos($_SERVER['HTTP_USER_AGENT'],"iPhone") !== false) { return true; } elseif (stripos($_SERVER['HTTP_USER_AGENT'],"iPad") !== false) { return true; } elseif (stripos($_SERVER['HTTP_USER_AGENT'],"iPod") !== false) { return true; } return false; }
?>
To solve this use
$tr = new Zend_Mail_Transport_Sendmail('-fmail@example.com'); $_mail = new Zend_Mail('ISO-8859-1'); $_mail->setDefaultTransport($tr);
and wooo it works
I had issues with the zend framework and its implementation of lucene. It saved the values from my UTF-8 database in the lucene files with characters like UTF-8 in ISO 8859-1 like on the search result page. And I wasn’t able to search case insensitive.
I noticed that the apache header (zend server CE) wasn’t sending UTF-8. So I added AddDefaultCharset utf-8 to my httpd.conf. Didn’t help.
What helped: In the Bootstrap.php adding to the init of the search
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8()); Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8'); Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
In the model it is needed to decode it to ISO 8859-1 and than save it as UTF-8. Sounds insane, but it was the only thing that works for me.
$doc->addField(Zend_Search_Lucene_Field::Text('lucene_DB_CLOUMN_NAME',utf8_decode($db_apater_result['DB_CLOUMN_NAME']),'UTF-8'));
WTF Zend Lucene!
If you try to do an ajax request on a different domain. You’ll get nothing. Looking a bit deeper into the request I noticed that the status code isn’t 200 or 403 nor 404 like expected. Nope it is 0. (jquery ajax statusCode 0). This means the browser doesn’t allow a crossdomain request. The easiest way for me to solve this was to create a proxy php script. Now I can send my ajax request to a url on my server while the PHP script does the real request to the other server.
This is the php script
/** * GetFromHost() * * @param string $host * @param int $port * @param string $path * @param string $referer * @param bool $keepalive * @return */ function GetFromHost($host, $port, $path, $referer,$keepalive=false) { $fsocket = fsockopen($host, 80, $errno, $errstr, 30); if($fsocket){ $request = "GET $path HTTP/1.1\r\n"; $request .= "Host: $host\r\n"; $request .= "Referer: $referer\r\n"; $request .= 'User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) '; $request .= "Gecko/20021204\r\n"; $request .= 'Accept: text/xml,application/xml,application/xhtml+xml,'; $request .= 'text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,'; $request .= "image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1\r\n"; $request .= "Accept-Language: en-us, en;q=0.50\r\n"; //$request .= "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n"; $request .= "Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66\r\n"; if($keepalive==true){ $request .= "Keep-Alive: 300\r\n"; $request .= "Connection: keep-alive\r\n"; } else { $request .= "Connection: close\r\n"; } //$request .= "Content-Type: application/x-www-form-urlencoded\r\n"; //$request .= "Content-length: ". strlen($data_to_send) ."\r\n"; $request .= "\r\n"; //$request .= $data_to_send; fputs($fsocket, $request); $res =''; while(!feof($fsocket)) { $res .= fgets($fsocket, 1024); } fclose($fsocket); return $res; } else { return false; //echo "Fehlgeschlagen: ".$fsocket . $host .':'. $port; } } $x = GetFromHost("www.example", "80", "/deep/url/kinda/", ""); $x = explode('Content-Type: text/html',$x); $output = preg_replace('/\s+(\r\n|\r|\n)/', '$1', $x['1']);//remove white space and tabs at the line ends echo $output;
maybe you have to edit the explode part for server to separate the header fom the real content.
Archives by Subject:
- Categories
Archives by Month:
- November 2019
- October 2019
- May 2019
- April 2019
- March 2019
- January 2019
- October 2018
- August 2018
- June 2018
- April 2018
- March 2018
- February 2018
- November 2017
- June 2017
- April 2017
- February 2017
- January 2017
- November 2016
- September 2016
- May 2016
- February 2016
- September 2015
- August 2015
- July 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- July 2014
- June 2014
- April 2014
- January 2014
- December 2013
- August 2013
- July 2013
- June 2013
- May 2013
- April 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- August 2012
- July 2012
- June 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009