php

Solve Uncaught exception ‘Zend_Json_Exception’ with message ‘Decoding failed: Syntax error

15 Feb , 2012  

Using Zend_JSON for parse invalid JSON format like “pain in the neck”. If you got this kind of error while parse JSON :

1
Uncaught exception 'Zend_Json_Exception' with message 'Decoding failed: Syntax error

Or maybe :

1
Uncaught exception 'Zend_Json_Exception' with message 'Decoding failed: Unexpected control character found

I suggest to you, move into json_decode() from native PHP. Here are snippets to handle JSON invalid format exception.
More…

, ,

php

Preg_replace regex delete tags link url completely with text inside using php

31 Dec , 2011  

We need to completely remove anchor links with text inside using PHP. Then, we can use preg_replace() and removing all tags links with string completely by :

1
preg_replace('/<a[^>]*>(.*)</a>/iU','', $text);

Or seconds alternative is :

1
preg_replace('#(<a.*?>).*?(</a>)#', '', $text);

Now you can remove / delete all anchor links :)

,

php

Preg_replace regex remove domain name in text / string using PHP

31 Dec , 2011  

This is how to remove any domain name (TLD) in text or string using preg_replace in PHP. Basically, we want to get rid off any domain name in text for instance :

This is paragraph that contain many text and string also with some domain name called : wpscale.com

To strip off the domain name in paragraph :
More…

,

php

Run latest PhantomJS with shell_exec PHP on Ubuntu 11.10 Oneiric

24 Dec , 2011  

Running PhantomJS with exec() or shell_exec PHP and grab it results may lead you into several headache problems. Several web that talking how to run phantomjs in PHP just send me into fail results. I will show you several pitfalls for instance, here a small scripts to run PhantomJS :

test.php :

1
2
3
4
<?php
$result = shell_exec('phantomjs --version');
echo $result;
?>

More…

,

php

How to install and solve problem php-pear Mediawiki TextWiki in Ubuntu

3 Dec , 2011  

I facing problem when parsing MediaWiki result using php-pear in Ubuntu 11.10 ( Oneiric ). It give me error result like this :

1
2
3
4
require_once(): Failed opening required ''
Warning: require_once(Text/Wiki/Mediawiki.php): failed to open stream: No such file or directory in /usr/share/php/Text/Wiki.php on line 473

Fatal error: require_once(): Failed opening required 'Text/Wiki/Mediawiki.php' (include_path='.:/usr/share/php:/usr/share/pear:/home/ubuntu/htdocs/...') in /usr/share/php/Text/Wiki.php on line 473

More…

,

php

How to solve tmp/cache/ is not writable [CORE/cake/libs/cache/file.php, line 267] app/tmp/cache/persistent/ is not writable [CORE/cake/libs/cache/ file.php, line 267]

19 Aug , 2011  

Today i got this kind of error in my CakePHP 1.3. Here are the error code :

1
tmp/cache/ is not writable [CORE/cake/libs/cache/file.php, line 267] app/tmp/cache/persistent/ is not writable [CORE/cake/libs/cache/ file.php, line 267]

I tried to solve this by chmod and change permisssion recursive into app/tmp.

1
2
cd app/
chmod 777 -R tmp

Hey, after change permission, it’s still give me error. What happen here? After walking around and analyze the error, i found the problem. It’s because i use file caching built-in CakePHP. So, i better disable it’s by editing app/config/core.php :

1
2
3
4
5
if($_SERVER['SERVER_NAME'] == 'localhost') {
   Configure::write('Cache.disable', true);
}else{
   Configure::write('Cache.disable', false);
}

This fixed my CakePHP in localhost. Now, time to works again and swipe another errors :)

,

php

How to create template system layouts in CodeIgniter 2.0

17 Jul , 2011  

Templating in CodeIgniter, it’s mean we should make your own layouts system. If you have using CakePHP before, then you see there no automatic templating views in CodeIgniter. After searching and compare with anothers, i get Philsturgeon template is near with CakePHP template system ( http://getsparks.org/packages/template/show ).

So, first step, download and install it. See the installation guide to make your step easier. I assume you have installed the template into your CodeIgniter successfully. I load this template system in autoload.php $autoload['libraries'] = array('database','session','template');.
More…

,

php

Solving RSS Feed error in Codeigniter 2.0

17 Jul , 2011  

There are several commmon error when building RSS Feed in CodeIgniter 2.0. Somehow we made mistakes and here are top list case.

When we got ErrorException [ Parse Error ]: syntax error, unexpected T_STRING, this happen because you have PHP short_tags enabled, which means <? is shorthand for <?php and opens a PHP code block.

To fix this, turn off short_tags in php.ini or code like this :

1
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

Another problem is Line Number 1, Column 2: <?xml version="1.0" encoding="utf-8" ?>. This usually happen because we close our documents with ?> php tags. In CodeIgniter, we should leave our end of file without using ?>.

So, when you facing another RSS Feed error, try to check your php.ini and use CodeIgniter code behaviour.

,

php

How to fix Codeigniter blank / white page error

17 Jul , 2011  

Sometimes when we developing our Codeigniter application, suddenly it gave us White of Screen or blank page error. To solve this problem, we need to configure our PHP.ini to show error. So, if you using Ubuntu, go to /etc/php5/apache2/php.ini and edit :

1
2
error_reporting = E_ALL | E_STRICT
display_errors = On

More…

,

php

How to use Zend Framework in CodeIgniter 2.0

17 Jul , 2011  

Combine Zend Framework with Codeigniter will give great result and cutting development time. Intergrating Zend Framework into CodeIgniter 2.0 is very easy. First, you download new Zend Framework here . After downloading, unpack it package and get Zend folder. Put this Zend folder into app/libraries in CodeIgniter.

Then, we create Zend libraries :
More…

,