發表文章

目前顯示的是有「php」標籤的文章

web compare: PHP vs ASP.NET vs JAVA + JSP

Here are a few pro's and con's of the languages: PHP ASP.NET Java + JSP Pro's 1. User friendly, java/javascript type syntax 2. Minimal learning curve for small applications 3. Great array of functions predefined in the system 4. Loads of cheap hosting options 5. Loads of tutorials and pre-written scripts 1. OOP based environment. 2. Allows for rapid development inside the correct IDE's 3. Strongly Typed 4. Java/javascript type syntax 5. Strong graphics manipulation ability 1. OOP 2. Strongly typed 3. Strong Graphics Manipulation ability 4. Loads of API's 5. Open Source Con's 1. Code can get messy quickly if project is not managed properly. 2. Not strongly typed 3. Security depends on the knowledge of the developer 4. Configurations might change depending on host 1. Costly IDE's 2. Steep learning curve for beginner 1. Slow performing IDE's 2. Steep learning curve

[PHP] get all URLs from text

Here is the way to get all URLs from text. 以下方法可以把全部連結拿出來. function findURLs($text){ $pattern = '/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)?/i'; @preg_match_all($pattern, $text, $matches); if($matches[0]){ return $matches[0]; }else{ return false; } }

[Magento] database configuration file

If you want to change the Magento database configuration file. You can find the file  local.xml  <DocumentRoot>/app/etc/ The code should be something like that: <config> <global> <install> <date><![CDATA[Tue, 30 Apr 2013 13:42:46 +0000]]></date> </install> <crypt> <key><![CDATA[f71bejhefa9510f00422fc8650f46c24]]></key> </crypt> <disable_local_modules>false</disable_local_modules> <resources> <db> <table_prefix><![CDATA[]]></table_prefix> </db> <default_setup> <connection> <host><![CDATA[localhost]]></host> <username><![CDATA[MyUserName]]></username> <password><![CDATA[MyPassword]]></password> <dbname><![CDATA[MydatabaseName]]></dbname> <initStatements><![CDATA[SET NAMES utf8]]></initStatements> <model><![CDATA[mysql4]]></model> ...

Get latest google trends with php

Get latest google trends with php Here we come to the fact that if you want traffic to your website it would be good to create posts about the subjects that people search the most which will lead to more visitors and visitors are money. I needed an automated way to extract google trends on hourly bases and store in my database so I can then use them. Google does not provide API for this so here is a script that scrapes google feed and extracts the keywords. <?php     $url = 'http://www.google.com/trends/hottrends/atom/feed?pn=p1';     $referrer = 'http://www.google.com';     $agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8';     $ch = curl_init();     curl_setopt($ch, CURLOPT_URL, $url);     curl_setopt($ch, CURLOPT_HEADER, 0);     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     curl_setopt($ch, CURLOPT_HTTPPRO...

File manager for Web

elFinder 2.0 (rc1) jQuery and jQuery UI jQuery 1.6.1 or higher is required. If you use custom jQuery UI build than make sure selectable , draggable , droppable , resizable , dialog and slider are included. <link rel= "stylesheet" type= "text/css" media= "screen" href= "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/smoothness/jquery-ui.css" /> <script type= "text/javascript" src= "http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" ></script> <script type= "text/javascript" src= "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js" ></script> elFinder Include elFinder CSS and JS files. <link rel= "stylesheet" type= "text/css" media= "screen" href= "css/elfinder.min.css" > <script type= "text/javascript" src= "js/elfinder.min.js" ...

[Programming] Throw out a 'The Connection was reset' error after submiting (POST) form

Here are a number of reasons that may occurs error after submiting (POST) form: Too much parameter sent: Try to reduce the useless input before submit Reach the max input var: set "max_input_vars   1000" in php.ini or in PHP page Loading time too long: In particular, the values for max_execution_time and max_input_time could safely be increased. Both of these are currently set to 180 seconds, or 3 minutes Reach the max of files: Set " max_file_uploads   20" in php.ini or in PHP page Posting data too large: Set " post_max_size   28M" in php.ini or in PHP page Over memory: Set "memory_limit   128M" in php.ini or in PHP page

[PHP] to Detect if browser is mobile

Use PHP to detect if browser is mobile Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. Download from the following link. https://github.com/serbanghita/Mobile-Detect/tags How to use in php code require_once '../Mobile_Detect.php'; $detect = new Mobile_Detect; if($detect->isMobile() ){     // is mobile }else if($detect->isTablet()){     // is tablet }else{     // is computer } Source from: https://github.com/serbanghita/Mobile-Detect

[PHP] "time ago" function

To get a time different between now and input time if you want to check the different between now and set date. you can use this function. function   time_passed ( $timestamp ) {       //type cast, current time, difference in timestamps       $timestamp         =   ( int )   $timestamp ;       $current_time     =   time ( ) ;       $diff              =   $current_time   -   $timestamp ;             //intervals in seconds       $intervals         =   array   (           'year'   =>   31556926 ,   'month'   =>   2629744 ,   'week'   =>   604800 ,   'day'   =>   86400 ,   'hour'   =>   3600 ,   'minute' =>   60     ...