Recently i have an client who wants to embeded the FormSite form in the a Drupal 6 website. But after i insert the embedded code in the node body with Full HTML or PHP Code filters. Nothing is shown. For example, if i enter the following code in the node body.
Continue reading Drupal – Embed inline Javascript in node body
Category Archives: PHP
PHP – Prevent GIF image loaded from browser cache
I would like to show a GIF image on a website but i found that the animation is not working as the browser caches the GIF image after first load. Here is a PHP workaround by adding the current timestamp to the image src url.
<img src="https://eureka.ykyuen.info/example.gif?v=<?php echo Date("Y.m.d.G.i.s"); ?>" />
Done =)
Reference: cache woes, how to force an image to refresh or load fresh
PHP – Check if duplicated values exists in array
The following function could help you to check if there is any duplicated values in an given array.
function has_dupes($array) {
$dupe_array = array();
foreach($array as $val){
if(++$dupe_array[$val] > 1){
return true;
}
}
return false;
}
Done =)
Reference: StackOverflow – php: check if an array has duplicates
PHP – Encoding problem in mail()
If you have encoding problem when using mail(). You could consider using mb_send_mail(). Here is an example written by Taslim Mazumder Sohel.
Continue reading PHP – Encoding problem in mail()
PHP – Send HTML Email
If you want to send HTML email using the PHP mail(), here is an example.
Continue reading PHP – Send HTML Email
PHP – String startsWith and endsWith
The following 2 functions could check if a string starts/ends with another string.
/* Return TRUE if $needle is empty */
function startsWith($haystack, $needle) {
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
/* Return TRUE if $needle is empty */
function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return TRUE;
}
$start = $length * -1;
return (substr($haystack, $start) === $needle);
}
Please note that if the $needle is empty, both functions will return TRUE.
Done =)
Reference: StackOverflow – PHP startsWith() and endsWith() functions
Drupal – Create PDF file with dompdf
dompdf is a HTML to PDF converter in PHP. In the GShop project, I need it for sending email with PDF attachment by the Ubercart Conditional actions in Drupal. The following example is done in Drupal 6 with Ubercart.
1. Download and extract the dompdf library to <drupal>/sites/all/libraries.
Continue reading Drupal – Create PDF file with dompdf
PHP – Convert URL into clickable link with UrlLinker
Yesterday we have talked about converting URL into clickable link by Regular Expression.
PHP – Convert URL into clickable link by Regular Expression
If you want a more complete and robust solution, you can try the UrlLinker written by Søren Løvborg.
Continue reading PHP – Convert URL into clickable link with UrlLinker
PHP – Convert URL into clickable link by Regular Expression
I want to convert the all URLs in a string into clickable links. I found a solution in StackOverflow but probably it only works in PHP 5.2 since it uses eregi_replace() which is deprecated in PHP 5.3. So use it with cares.
Continue reading PHP – Convert URL into clickable link by Regular Expression
PHP – Write an Array/Object to File by print_r()
In debugging PHP program, i always use print() and print_r() to output the variable content to the browser. But this does not work when we are not using browser. A simple way to get the content is to write it to a file.
I found a nice post written by Ivan which provides this simple way with just a few lines of code.
Ivan Kristianto – [TIPS] Write print_r() Output To File Continue reading PHP – Write an Array/Object to File by print_r()