We can use the PHP cURL library to generate simple HTTP POST request. The following example shows you how to create a simple SOAP request using cURL. Continue reading PHP – Send a SOAP Request by cURL
Category Archives: PHP
PHP – dompdf render() timeout problem
I found a very good post which demonstrate how to integrate dompdf in CodeIgniter.
CodeIgniter Wiki – PDF generation using dompdf Continue reading PHP – dompdf render() timeout problem
PHP – dompdf UTF-8 decode problem
The dompdf is a PHP library which help you to convert HTML into a PDF file. Actually i haven’t tried to implement it by myself but recently, i followed an project which used the dompdf and there is a UTF-8 decoding issue for special character like an Apostrophe. Continue reading PHP – dompdf UTF-8 decode problem
PHP – Date Formatting and strtotime()
Here are some examples of date formatting in PHP. Continue reading PHP – Date Formatting and strtotime()
Configure Postfix/Sendmail for PHP mail() in Ubuntu
Actually configure Postfix or Sendmail for PHP mail() is the same. Both of them run the /usr/sbin/sendmail binary. It is quite confusing if we just look at the name of the binary but this is what Postfix did.
For more information, take a look at the Postfix Manual – sendmail.
For the PHP setting, open the /etc/php5/apache2/php.ini and configure the sendmail_path. Continue reading Configure Postfix/Sendmail for PHP mail() in Ubuntu
PHP – Check Even and Odd Number
Just find a very cool way to check if the number is a even or odd using &1 in PHP.
foreach(range(0,12) as $number) {
$result = $number&1 ? "odd" : "even";
print "$number: $result<br />";
}
Done =)
Reference: How to check if a number is odd or even
PHP – Convert Big5 to UTF-8
I am not familiar with the character encoding. I have a ISO-8859-1 string(Big5). After i convert it to UTF-8 by the utf8_encode() function, garbage characters are shown in the HTML. Finally, i found another way to convert Big5 to UTF-8.
The following function will break down a Big5 string into characters and convert them into UTF-8 one by one. Continue reading PHP – Convert Big5 to UTF-8
PHP – Convert Special Characters to HTML Entities
I was working on a legacy CMS which has a HTML form with ISO-8859-1 encoding. I found that whenever i got an Apostrophe (‘) in the string, the data cannot be persisted.
I guess it should be some encoding problem which makes the database fail to persist the data. So i try to use the PHP str_replace function to replace those Apostrophe but it has never replaced them successfully.
Finally, i got the solution. PHP provide a function called htmlspecialchars which will substitute the following special characters into HTML entities. Continue reading PHP – Convert Special Characters to HTML Entities
PHP – Generate A Random String
The following piece of code could generate a random string with a specified length.
Continue reading PHP – Generate A Random String
PHP – Send Attachment with PHP mail()
Update @ 2014-03-10: If the following piece of code doesn’t work, you could try the comment written by karmaprod.
Update @ 2014-01-17: You may need to change the PHP_EOL setting in Windows environment as suggested by Rene.
Update @ 2015-02-13: Replace all “/r/n” to PHP_EOL as suggested by Rene and Tomas for windows environment and sending image attachment.
By default, the PHP mail() does not support sending email with attachment. In order to send an attachment, u can either use the PEAR package or PHPMailer. But in reality, the hosting server may not provide these kinds of third party libraries.
Continue reading PHP – Send Attachment with PHP mail()