跳至主要内容

博文

目前显示的是标签为“php”的博文

how to install imagemaick and php_imagick.dll in windows

1. check vredist_x64 and vredist_x86 is installed correctly. 2. install the correct version of imagemagic and php_imagick.dll, if you got "module not found " inthe folder you are sure your dll is in  it, maybe is your imagemagic and php_imageik.dll is not fit. at least: this for sure works: I have Imagick working on Win7 x64 with PHP 5.4 (only tested commandline, but Apache should work) using the beta libraries as compiled and hosted here:  http://www.peewit.fr/imagick/ I installed ImageMagick via the ImageMagick-6.8.0-7-Q16-windows-dll.exe file on the  http://imagemagick.spd.co.il/binaries/

phpunit test get error: No tests found in class "xxx" , solution

if you get this error, like me use this: use Symfony\Component\HttpFoundation\Request; abstract class BaseControllerTestCase extends WebTestCase { ... } if you do not add the abstract infront of it, it will consider this class contains some test case, but in fact this class is not used to test, just a extend of webtestcase. So to avoid this error, you need add abstract for this class. Anyway, this class will never generate an object.

save tiff image.

a backup of tiff transform. public function __construct($path,$minSize,$minWidth,$minHeight){ $this->path=$path; $this->minSize=$minSize; $this->minWidth=$minWidth; $this->minHeight=$minHeight; } public function setImage(SmallAdds $ad){ $this->today=date('Y-m-d'); $this->fullImagePath=$this->path.$ad->getSitePath().$this->today."/"; if (!is_dir($this->fullImagePath)){ if (!mkdir($this->fullImagePath,0775, true)) throw new \Exception('can not create folder'); } $this->ad=$ad; $this->name=uniqid(); } public function createPhoto(){ try{ $this->photo=new Photo(); $this->photo->setSmallAdds($this->ad); $imagePath = $this->fullImagePath; $pngName=$imagePath.$this->name.".png"; $tifName=$imagePath.$this-...

remove html tag in string.

An obvious simple solution is to run strip_tags() over it, but that would simply remove tags and leave all text content intact, including embedded javascript and CSS, as well as all text inside elements that are normally hidden (e.g. by setting display: none on them). You could try some regex magic to filter out the parts you're not interested in, but regular expressions on HTML are generally a bad idea for anything nontrivial. The ultimate solution is, I'm afraid, to use a proper HTML parser and then pull the actual text out of the resulting DOM tree - by the time you have that, you'll be pretty close to implementing a web browser. form: http://stackoverflow.com/questions/5572469/get-html-output-cleaned-text-with-php

php array function

a good explaination for array_merge, +. array_push http://www.java-samples.com/showtutorial.php?tutorialid=997 You want to combine two arrays into one. Use  array_merge( ) : $garden = array_merge($fruits, $vegetables); The  array_merge( )  function works with both predefined arrays and arrays defined in place using array( ) : $p_languages = array('Perl', 'PHP'); $p_languages = array_merge($p_languages, array('Python')); print_r($p_languages); Array ( [0] => PHP [1] => Perl [2] => Python ) Accordingly, merged arrays can be either preexisting arrays, as with  $p_languages , or anonymous arrays, as with  array('Python') . You can't use  array_push() , because PHP won't automatically flatten out the array into series of independent variables, and you'll end up with a nested array. Thus: array_push($p_languages, array('Python')); print_r($p_languages); Array ( [0] => PHP [1] => Pe...

DateTime 不能用=来复制

$date1 = new DateTime (); $date2 = new DateTime (); $date2 -> add ( new DateInterval ( 'P3Y' )); This seems pretty damn obvious, so if I'm just not understanding, let me know. Update: If you want to copy rather than reference an existing DT object, use  clone , not  = . $a = clone $b;

ps_files_cleanup_dir pemission denied

今天遇到 session_start(): ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied 这个错误 ,因为php没100此session start就会尝试清除一次session 的cache,但是 显然/var/lib/php5的权限是root,而且在/etc/cron.d/php5中已经有一个定时清理器是root的,所以需要把php.ini 中的 session.gc_probability 改为0.

php pear install phpunit 的问题

http://www.ankara-gtug.org/2011/11/15/phpunit-installation-on-wamp-in-windows-7-and-integration-with-eclipse-2/ 详细的讲解如何安装pear 和安装phpunit,但是当我执行: pear install pear.phpunit.de/PHPUnit 的是后,总是告诉我: No releases available for package "pear.phpunit.de/PHPUnit" install failed 查找之后发现需要: pear clear-cache 然后再执行就没有问题了。

weather api

12-09-2012 , well, after a study, a  CORS (cross origin resource sharing) is not allowed in IE 9, so  we can never use javascript to do this, google weather is depracated. use yahoo weather api instead.  before, we can use a google api like this: foreach ($this->codep as $value) { if ($value==null || $value=="") continue; $fp = @fopen("http://www.google.com/ig/api?weather=". $value.",france", "r"); break; } if (!$fp){ return false; } $gt = ""; while (!feof($fp) ) { $gt .= fgets($fp, 4096); } $p1 = strpos($gt, " "); $p2 = strpos($gt, " "); $gt2 = substr($gt, $p1, ($p2 - $p1)); preg_match("/humidity data=\"Humidity: ([^\"]*)%\"/", $gt2, $humidite); preg_match("/wind_condition data=\"Wind: ([^\"]*) at ([^\"]*) mph\"/", $gt2, $vent); preg_match("/icon data=\"([^\"]*)\"/", $gt2, $l...

Single Sign On (sso)

Well, let me explain a bit further then. (All URLs are fictional!) As I said, the visitor goes to http://www.yourwebpage.com  and indicates he wants to log in. He is redirected to http://your.loginpage.org?return=http://www.yourwebpage.com/Authenticated  where he will have to provide his username and password. When his account information is valid, he will return to the page that was provided in the login URL, but with an additional parameter that will be used as ID. Thus, he goes to http://www.yourwebpage.com/Authenticated?ID=SharedSecret  where SharedSecret would be a temporary ID, valid for 30 seconds or less. When your authentication page gets called, the page would then call a method that's shared between yourwebpage.com and loginpage.org to look for the account information of SharedSecret to retrieve a more permanent ID. This permanent ID is stored in the web session of yourwebpage.com and should NEVER be shown to the user. The shared method could be anything. If...

avoid using switch

今天读了一个关于怎样避免使用switch的blog,觉得他的想法甚好,虽然本身是基于javascript的,但其实可以用在任何语言上,只要能支持通过变量的值来call function就可以了。 例子如下: switch (something) { case 1: doX(); break; case 2: doY(); break; case 3: doN(); break; // And so on... } var cases = { 1: doX, 2: doY, 3: doN }; if (cases[something]) { cases[something](); } 就像他所说的,不仅仅是因为后面的更简单或者更清晰,而且因为他更容易扩展,它把实现和定义分开了,你可以在服务器端加你所有想增加的function,而实现则是统一的。就像我以前做的php的controller 一样, $functionName=$_GET['action'].'Action'; $controller->$functionName(); 外面可以加一个catch exception,如果这个action 不存在的话。

关于html形式的mail

今天看到一篇文章讲如何写richtext的mail。链接: http://css-tricks.com/using-css-in-html-emails-the-real-story/ 有几个要注意的地方: 不能用< head> 不能用外部style sheet 不能用background-image或者background-position 不能用float 不能用margin 不能用font 这里有一个url让我们把一个正常的html变成一个mail能用的html。 http://premailer.dialect.ca/ 对写恶心的htmlmail很有帮助

uploadify出问题以后的解决办法

其实这也应当是所有flash的问题,当出现错误的时候就什么提示信息都没有,有几个解决办法。 1.在服务器端的响应文件里写入log。 2.通过使用http://www.charlesproxy.com/download/latest-release/download.do这种网络监测软件来监测网络通信状况。当然需要在php.ini中打开display_errors”,通常这种信息不能在firebug中显示,因为不是由firefox发出的请求。