<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>PHP on Lin's Blog</title><link>https://coder.tw/en/tags/php/</link><description>Recent content in PHP on Lin's Blog</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 12 Dec 2016 04:57:46 +0000</lastBuildDate><atom:link href="https://coder.tw/en/tags/php/index.xml" rel="self" type="application/rss+xml"/><item><title>Laravel Artisan Migrate "Table Already Exists" or "Foreign Key" Error</title><link>https://coder.tw/en/posts/laravel-artisan-migrate-table-already-exisis-or-foreign-key-error/</link><pubDate>Mon, 12 Dec 2016 04:57:46 +0000</pubDate><guid>https://coder.tw/en/posts/laravel-artisan-migrate-table-already-exisis-or-foreign-key-error/</guid><description>&lt;p&gt;While deploying a project I had developed half a year earlier with Laravel 5.2, I ran into quite a few problems. One of them: after running php artisan migrate, I got a &amp;ldquo;Table Already Exists&amp;rdquo; error. But I had never created that table before. Digging deeper, I found that the table did exist, but there was no record for it in the project_migrations table. So I deleted the table manually and ran php artisan migrate once more. Sure enough, this time the real error message appeared: &amp;ldquo;General error: 1005 Can&amp;rsquo;t create table &amp;lsquo;dbname.#sql-fbc1_15e6&amp;rsquo; (errno: 121) (SQL: alter table &lt;code&gt;karl_project&lt;/code&gt; add constraint &lt;code&gt;project_user_id_foreign&lt;/code&gt; foreign key (&lt;code&gt;user_id&lt;/code&gt;) references &lt;code&gt;karl_user&lt;/code&gt;
(&lt;code&gt;id&lt;/code&gt;))&amp;rdquo;&lt;/p&gt;</description></item><item><title>Facebook Graph API: How to Fix Missing Email Field for Some Users</title><link>https://coder.tw/en/posts/facebook-graph-api-missing-email-fix/</link><pubDate>Fri, 02 Dec 2016 12:18:56 +0000</pubDate><guid>https://coder.tw/en/posts/facebook-graph-api-missing-email-fix/</guid><description>&lt;p&gt;I recently ran into a rather interesting little problem. A contest voting system we built had occasional users who couldn&amp;rsquo;t vote. The system was built with Laravel. Users could log in with Facebook to vote for a designated entry, one vote per day. We only collected the most basic Email and Name data, for the prize draw. Everything was fine during testing, but after launch, a few users complained that after voting they saw the error message &amp;ldquo;whoops looks like something went wrong,&amp;rdquo; while most users could vote normally.&lt;/p&gt;</description></item><item><title>Compiling and Installing a PHP Extension Manually (Linux)</title><link>https://coder.tw/en/posts/compile-install-php-extension-linux/</link><pubDate>Thu, 26 Jan 2012 16:53:57 +0000</pubDate><guid>https://coder.tw/en/posts/compile-install-php-extension-linux/</guid><description>&lt;p&gt;If you want to install an extension for PHP, what should you do? Many people will answer Pecl. That is indeed a very convenient way to install extensions. But what if your server does not have Pecl? And what if, for some reason, you cannot install Pecl? Then you have no choice but to compile and install the extension manually~ This post shows you how to manually compile a PHP extension on Linux.&lt;/p&gt;</description></item><item><title>PHPConf Takeaways</title><link>https://coder.tw/en/posts/phpconf-taiwan-recap/</link><pubDate>Sat, 03 Dec 2011 17:57:20 +0000</pubDate><guid>https://coder.tw/en/posts/phpconf-taiwan-recap/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/12/phpconf2011_1318928649.png"&gt;&lt;img class="aligncenter size-full wp-image-774" title="phpconf2011_1318928649" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/12/phpconf2011_1318928649.png" alt="" width="403" height="178" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To be honest, my first language was VB, but the one I actually use most and know best is PHP. For example, when I took part in the Taipei City Software Competition, I solved every problem in PHP, since that&amp;rsquo;s what I know best~ So when I heard PHPConf was happening, I was so happy that I signed up to be a staff member XD&lt;/p&gt;</description></item><item><title>[PHP] Listing Files in a Folder with glob, scandir, and readdir</title><link>https://coder.tw/en/posts/php-glob-scandir-readdir-list-files/</link><pubDate>Wed, 17 Aug 2011 17:27:32 +0000</pubDate><guid>https://coder.tw/en/posts/php-glob-scandir-readdir-list-files/</guid><description>&lt;p&gt;Sometimes you need to write a PHP program that gets a list of the files in a specified folder. For example, I needed this feature when I was making an online hard drive program. Here I&amp;rsquo;ll introduce three functions that can all do this, though each is used a bit differently: glob, scandir, and readdir.&lt;/p&gt;</description></item><item><title>Changing PHP's Execution Time Limit to Keep Long-Running Scripts from Being Stopped</title><link>https://coder.tw/en/posts/php-max-execution-time-limit/</link><pubDate>Tue, 09 Aug 2011 15:04:03 +0000</pubDate><guid>https://coder.tw/en/posts/php-max-execution-time-limit/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/08/2011-08-09_150333.jpg"&gt;&lt;img class="alignnone size-large wp-image-678" title="2011-08-09_150333" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/08/2011-08-09_150333-540x423.jpg" alt="" width="540" height="423" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;By default, PHP has a 30-second execution limit. When a program runs longer than 30 seconds, you get an error like this: &amp;ldquo;&lt;strong&gt;Fatal error&lt;/strong&gt;: Maximum execution time of 30 seconds exceeded&amp;rdquo;. This is a safeguard against bugs, such as infinite loops or other strange code that could end up bringing the system down. However, sometimes your program really needs to run for more than 30 seconds. For example, you might be processing a very large file in PHP, such as a database backup that can be hundreds of MB, which takes a long time and can easily exceed 30 seconds. My earlier Plurk BOT and spider programs also ran into this easily. Here I&amp;rsquo;ll show you two ways to adjust this time limit.&lt;/p&gt;</description></item><item><title>How to Defend Against Basic SQL Injection in PHP?</title><link>https://coder.tw/en/posts/php-basic-sql-injection-defense/</link><pubDate>Tue, 02 Aug 2011 07:00:27 +0000</pubDate><guid>https://coder.tw/en/posts/php-basic-sql-injection-defense/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/08/2011-08-01_222010.jpg"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px; border-color: initial; border-style: initial;" title="2011-08-01_222010" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/08/2011-08-01_222010_thumb.jpg" alt="2011-08-01_222010" width="524" height="401" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For the past few days I&amp;rsquo;ve been writing a small program to organize contacts, so I&amp;rsquo;ve been researching quite a few things. While working on the database side, I wanted to guard against so-called SQL injection, where a malicious string is placed in a parameter to attack the database. So I applied some basic defenses. The following is how to add some basic protection against SQL injection~&lt;/p&gt;</description></item><item><title>How to Embed Arrays, $_POST, and $_GET Directly in a PHP String (SQL Query)</title><link>https://coder.tw/en/posts/php-embed-array-post-get-in-sql-string/</link><pubDate>Mon, 01 Aug 2011 14:23:03 +0000</pubDate><guid>https://coder.tw/en/posts/php-embed-array-post-get-in-sql-string/</guid><description>&lt;p&gt;Over the past few days, while writing a small program, I ran into a problem. I wanted to put a $_POST variable directly into my SQL query string instead of using the concatenation operator. But because of quoting issues, it took me quite a while to figure out how. Here is a brief introduction. I also want to thank Bu and Cang Shixian for teaching me this method! If it weren&amp;rsquo;t for them, I might still not know about it. Also, this method isn&amp;rsquo;t limited to $_POST; it works with other arrays too.&lt;/p&gt;</description></item><item><title>Solving Pascal's Triangle with a Formula! (Thanks to Cang Hai)</title><link>https://coder.tw/en/posts/pascal-triangle-formula-solution/</link><pubDate>Sun, 24 Jul 2011 08:25:37 +0000</pubDate><guid>https://coder.tw/en/posts/pascal-triangle-formula-solution/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/07/210px-PascalTriangleAnimated2.gif"&gt;&lt;img title="210px-PascalTriangleAnimated2" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/07/210px-PascalTriangleAnimated2.gif" alt="" width="210" height="194" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The image above is from Wikipedia and is used to explain Pascal&amp;rsquo;s triangle.&lt;/p&gt;
&lt;p&gt;Today&amp;rsquo;s topic is the so-called Pascal&amp;rsquo;s triangle. Some people also call it Yang Hui&amp;rsquo;s triangle or Jia Xian&amp;rsquo;s triangle. The first row&amp;rsquo;s first entry is &amp;ldquo;1&amp;rdquo;. Each number below equals the sum of the number to its upper left and the number to its upper right. If there is no number to the upper left or upper right, it counts as 0. For example, the second row has two numbers, &amp;ldquo;1, 1&amp;rdquo;. The third row is &amp;ldquo;1, 2, 1&amp;rdquo;. And this triangle can extend infinitely.&lt;/p&gt;</description></item><item><title>Quickly Building a Multilingual Program with Gettext for PHP</title><link>https://coder.tw/en/posts/php-gettext-multilanguage-program/</link><pubDate>Mon, 18 Jul 2011 22:47:40 +0000</pubDate><guid>https://coder.tw/en/posts/php-gettext-multilanguage-program/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/07/2011-07-18_224707.jpg"&gt;&lt;img class="alignnone size-large wp-image-555" title="2011-07-18_224707" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/07/2011-07-18_224707-540x378.jpg" alt="" width="540" height="378" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Gettext is a&amp;hellip; um, I&amp;rsquo;m not sure how to describe it. It&amp;rsquo;s something like a specification, but it&amp;rsquo;s also a set of libraries. Anyway, it makes it easy to make your program multilingual~ This article is about using Gettext with PHP to develop multilingual programs and websites.&lt;/p&gt;</description></item><item><title>PHP Documentation for Chrome - Look Up PHP Docs Quickly</title><link>https://coder.tw/en/posts/php-documentation-for-chrome/</link><pubDate>Sun, 29 May 2011 11:26:01 +0000</pubDate><guid>https://coder.tw/en/posts/php-documentation-for-chrome/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/05/2011-05-29_111813.jpg"&gt;&lt;img class="size-large wp-image-527 aligncenter" title="2011-05-29_111813" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/05/2011-05-29_111813-540x406.jpg" alt="" width="540" height="406" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;PHP is a fairly easy language to learn. It isn&amp;rsquo;t difficult in itself, and there are plenty of resources for it. In particular, the official PHP website provides a reference of PHP functions, where you can look up any PHP function. It&amp;rsquo;s quite similar to Microsoft&amp;rsquo;s MSDN. Today I want to introduce a Chrome extension that puts the search feature of the official PHP docs into your browser, so you can look up PHP functions more conveniently~&lt;/p&gt;</description></item><item><title>[Google API] Generating QR Codes with the Google Chart API, with PHP Example Code</title><link>https://coder.tw/en/posts/google-chart-api-qr-code-php/</link><pubDate>Thu, 24 Feb 2011 23:25:20 +0000</pubDate><guid>https://coder.tw/en/posts/google-chart-api-qr-code-php/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2011-02-24_230500.jpg"&gt;&lt;img class="size-large wp-image-328 aligncenter" title="2011-02-24_230500" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2011-02-24_230500-540x396.jpg" alt="" width="540" height="396" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this post, I&amp;rsquo;ll show you how to make QR codes with the Google Chart API. A QR code is the two-dimensional barcode that&amp;rsquo;s very popular right now. Generating a 2D barcode used to be a hassle, but with the Google Chart API, you can quickly generate a QR code from just a URL. I originally planned to write a post dedicated to the Google Chart API, but I decided to split it up instead~ (I also happened to come across the site &lt;a href="http://www.dotblogs.com.tw/shadow/archive/2011/02/24/21557.aspx" target="_blank"&gt;Shadow&amp;rsquo;s Tech Database&lt;/a&gt;, which introduces it, and I couldn&amp;rsquo;t resist writing about it~)&lt;/p&gt;</description></item><item><title>[PHP] [C++] A Concise Syntax for Explicit Type Casting</title><link>https://coder.tw/en/posts/php-c-explicit-type-cast/</link><pubDate>Tue, 15 Feb 2011 22:57:49 +0000</pubDate><guid>https://coder.tw/en/posts/php-c-explicit-type-cast/</guid><description>&lt;p style="text-align: center;"&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2011-02-15_225730.jpg"&gt;&lt;img class="size-large wp-image-282 aligncenter" title="2011-02-15_225730" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2011-02-15_225730-540x352.jpg" alt="" width="540" height="352" /&gt;&lt;/a&gt;&lt;/p&gt;
PHP and C++ have a very convenient way to cast types. You don't have to memorize a long list of conversion functions. You just put the target type in parentheses in front of the value. However, this approach seems to have some problems, though I'm not really sure what they are XD</description></item><item><title>[PHP] mb_convert_encoding: Some API Returned the Wrong Encoding? Convert It!</title><link>https://coder.tw/en/posts/php-mb-convert-encoding-big5-utf8-gbk/</link><pubDate>Fri, 04 Feb 2011 12:24:55 +0000</pubDate><guid>https://coder.tw/en/posts/php-mb-convert-encoding-big5-utf8-gbk/</guid><description>&lt;p&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2011-02-04_123628.jpg"&gt;&lt;img class="alignnone size-large wp-image-4662" title="2011-02-04_123628" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2011-02-04_123628-520x303.jpg" alt="" width="520" height="303" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;↑↑This is viewed in Chrome with Big5 encoding. The top is before conversion, and the bottom is after conversion.&lt;/p&gt;
&lt;p&gt;Yesterday, while playing with the Google Weather API, I found that it has a parameter for setting your language. If you don&amp;rsquo;t set it, the API returns English in UTF-8 encoding. But if you set zh-TW, it returns Chinese, encoded in Big5. So when using this API, I had to re-encode its return value to UTF-8 before I could use it. After all, there aren&amp;rsquo;t many Big5 websites left, so yesterday I went looking for the mb_convert_encoding function to do the encoding conversion for me~&lt;/p&gt;</description></item><item><title>Google Weather API - Get a Full Week of Weather Data</title><link>https://coder.tw/en/posts/google-weather-api-weekly-forecast-2/</link><pubDate>Fri, 04 Feb 2011 00:48:56 +0000</pubDate><guid>https://coder.tw/en/posts/google-weather-api-weekly-forecast-2/</guid><description>&lt;p style="text-align: center;"&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2011-02-04_004255.jpg"&gt;&lt;img class="size-large wp-image-4648 aligncenter" title="2011-02-04_004255" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/02/2011-02-04_004255-520x416.jpg" alt="" width="520" height="416" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;strong&gt;Google Weather API&lt;/strong&gt; is something I discovered today. I wanted to add a weather lookup feature to the Plurk bot I've been developing recently, so I searched online for ways to get weather data. My original plan was to read the Central Weather Bureau's web pages and parse the data there. But then I found that both Google and Yahoo offer weather APIs. I preferred the Google Weather API, because it returns XML, which is easier to parse. Yahoo, on the other hand, returns HTML... Also, the Google Weather API lets you specify a city name directly. For example, if I want the weather for Taipei City, I just pass "Taipei" to the API. Yahoo's weather API isn't that simple, though. You have to enter a city code, which means I'd need to look up the code for the city I want before I could use Yahoo's API.
&lt;h2&gt;</description></item><item><title>[PHP] Getting the Real Download URLs of Wretch/Yam Music with curl-lib</title><link>https://coder.tw/en/posts/php-curl-get-yam-music-download-url-2/</link><pubDate>Tue, 25 Jan 2011 18:31:04 +0000</pubDate><guid>https://coder.tw/en/posts/php-curl-get-yam-music-download-url-2/</guid><description>&lt;p style="text-align: center;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;a href="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/01/2011-01-25_182313.jpg"&gt;&lt;img class="size-large wp-image-4437 aligncenter" title="2011-01-25_182313" src="https://pub-6c026d2742d14927bfa2d850c31eac91.r2.dev/wp-content/uploads/2011/01/2011-01-25_182313-520x356.jpg" alt="" width="520" height="356" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="text-align: center;"&gt;The UI I designed is clean^^&lt;/p&gt;
This program, &lt;strong&gt;getting the real download URLs of Wretch/Yam music&lt;/strong&gt;, was originally going to become a program that automatically generates blog music code. But since many people already run music code generators, one more wouldn't make much of a difference. So instead of building it, I decided to release the code for everyone to look at. Also, if anyone needs to download music from Yam or Wretch, they can download the program, install it on their own server, and run it there.</description></item><item><title>PHP Probe: Checking How Stable Your Hosting Space Is</title><link>https://coder.tw/en/posts/php-probe-check-hosting-performance/</link><pubDate>Sun, 14 Jun 2009 14:53:09 +0000</pubDate><guid>https://coder.tw/en/posts/php-probe-check-hosting-performance/</guid><description>&lt;p&gt;I imagine many people building a website start out on free web hosting.
You&amp;rsquo;re probably also curious whether your host is stable, and how fast it is.
Today I came across an article on a free site where someone used a PHP probe to check their hosting, so here it is for everyone to try~~~~&lt;/p&gt;
&lt;p&gt;First, download the &lt;a href="http://goo.gl/X2XX "&gt;PHP probe&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Source Code Sharing - HOT SCRIPTS</title><link>https://coder.tw/en/posts/source-code-sharing-hot-scripts/</link><pubDate>Sat, 02 May 2009 03:42:00 +0000</pubDate><guid>https://coder.tw/en/posts/source-code-sharing-hot-scripts/</guid><description>&lt;p&gt; When you&amp;rsquo;re writing code, you often need to look for source code to use as a reference, right?&lt;br/&gt;
Here&amp;rsquo;s a website that is said to be the largest source code sharing site in the world.&lt;br/&gt;
I don&amp;rsquo;t think it&amp;rsquo;s really the largest, but it&amp;rsquo;s definitely among the top two :)&lt;br/&gt;
URL: &lt;a href="http://www.hotscripts.com/"&gt;http://www.hotscripts.com/&lt;/a&gt;&lt;br/&gt;
&lt;br/&gt;
When you enter this website, you&amp;rsquo;ll see the category page.&lt;br/&gt;
The categories are organized by programming language.&lt;br/&gt;
The main ones are PHP, CGI, ASP, Perl, Java Scripts&lt;br/&gt;
.AJAX, C &amp;amp; C++, Ruby On Rails (RoR), Python, and so on, with source code for each.&lt;br/&gt;
You can pick the language you want to use and then browse through it slowly.&lt;br/&gt;
Or you can use the search function in the upper-right corner.&lt;br/&gt;
But don&amp;rsquo;t type Chinese.&lt;br/&gt;
Because this is a foreign website, there isn&amp;rsquo;t much Chinese code.&lt;br/&gt;
You can also search within certain categories,&lt;br/&gt;
or search everything (the one that says All&amp;hellip;&amp;hellip;&amp;hellip;..).&lt;br/&gt;
Just select it from the dropdown menu in the search box.&lt;br/&gt;
&lt;img src="http://nwufiq.bay.livefilestore.com/y1pNsHnQXSOq5V3Hz3O2X4D4KWbr81NSSbiy6cHgqFGULbhfIl864I77Gn5exRpEykxzOtg2M1Xp71NfLDVBIEzh7n2S7o0RrBi/2009-05-02_114949.png" alt=""/&gt;&lt;br/&gt;
&lt;br/&gt;
Once you&amp;rsquo;ve found the program you want, you can take a quick look at its description.&lt;br/&gt;
&lt;img src="http://nwufiq.bay.livefilestore.com/y1pYNUI2Br39E1fDbCbiMIf3RzLwc-aKMbmDBkAiDigeJc2G6DOcklJ4KXCwOCD-0hw5Haj6C94QFvjWAsaRH7s1raYcDHEH74z/2009-05-02_115555.png" alt=""/&gt;&lt;br/&gt;
&lt;br/&gt;
If you want to download it, just click the Download button in the window.&lt;br/&gt;
&lt;img src="http://nwufiq.bay.livefilestore.com/y1p_iIOwTpQqpqMFN1OBhxaDeRbEF8uSS26XxFmS5YrRhCtwblyB0pWntbC8WRxWR7eR9RGdXdVmfGZyufrXFVP2_jYV5CH0Iil/2009-05-02_115711.png" alt=""/&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
One more thing to note: some programs are paid.&lt;br/&gt;
Usually the ones marked with a (Sponsor) badge are paid.&lt;br/&gt;
This website also offers account registration.&lt;br/&gt;
In fact, I never needed to register an account when I used it.&lt;br/&gt;&lt;/p&gt;</description></item></channel></rss>