Category Archives: PHP

PHP – Suppress and catch file_get_contents() warning

If you come across the following error when using file_get_contents().

  • Warning: file_get_contents(www.example.com) [function.file-get-contents]: failed to open stream:

 

One simple solution is to suppress the warning by adding @ in front of the file_get_contents() and check its returned value. Continue reading PHP – Suppress and catch file_get_contents() warning

PHP – PHP 5.3 Repository for CentOS from Webtatic.com

Webtatic.com provides its own repository. If you want to get the latest packages such as PHP and MySQL, you can consider adding it to your yum repo by the following steps.

1. Add the yum repository information

Continue reading PHP – PHP 5.3 Repository for CentOS from Webtatic.com

PHP – Swap Array Elements By Array Keys

The following PHP function could swap the array elements by the array keys.

function array_swap_assoc($key1, $key2, $array) {
  $newArray = array ();
  foreach ($array as $key => $value) {
    if ($key == $key1) {
      $newArray[$key2] = $array[$key2];
    } elseif ($key == $key2) {
      $newArray[$key1] = $array[$key1];
    } else {
      $newArray[$key] = $value;
    }
  }
  return $newArray;
}

Continue reading PHP – Swap Array Elements By Array Keys

Drupal – Send SOAP Request by NuSOAP

In PHP, we can use cURL library for generating SOAP request.
PHP – Send a SOAP Request by cURL

Except using the cURL library, we can also use the NuSOAP. The NuSOAP provides much more convenient way to create the SOAP request and it can be used in Drupal. The following example is base on the Blog post written be Eric London.
Executing a SOAP call from Drupal using nusoap Continue reading Drupal – Send SOAP Request by NuSOAP