Tag Archives: php

CodeIgniter, PHP source code not compiled

I’v uploaded a CodeIgniter application from my localhost with Apache to a server running Nginx.
Its works perfectly on my localhost and on other server with Apache.
It’s under a subdomain, an domain and other subdomains are running PHP 100%.
This application in CI doesn’t start, and PHP is returned without being compiled.

This is what I get on /var/log/nginx/error.log:

2013/12/05 14:50:31 [error] 20139#0: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Class 'M_website' not found in /home/webroot/domain.com/cms/system/core/Loader.php on line 303" while reading upstream, client: 84.91.4.220, server: cms.domain.com, request: "GET /websites HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cms.domain.com"

Why the problem?

CI files were starting with

<?

and not with

<?php

Solution

Had to edit /etc/php5/fpm/php.ini and set short_open_tag from Off to On and restart php-fpm.

service php5-fpm restart

 

This is how I solved it… simple issue to solve.

php rss feed to json

This is a simple script that grabs a rss file and converts it to json.
It was copied from http://onwebdev.blogspot.com/2011/08/php-converting-rss-to-json.html but it has some little changes that will work 100%!

In fact the original code was putting every title, description, pubDate and guid in a new array entry.

$feed = new DOMDocument();
 $feed->load('file.rss');
 $json = array();
 $json['title'] = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('title')->item(0)->firstChild->nodeValue;
 $json['description'] = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('description')->item(0)->firstChild->nodeValue;
 $json['link'] = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('link')->item(0)->firstChild->nodeValue;
 $items = $feed->getElementsByTagName('channel')->item(0)->getElementsByTagName('item');

 $json['item'] = array();
 $i = 0;

 foreach($items as $key => $item) {
 $title = $item->getElementsByTagName('title')->item(0)->firstChild->nodeValue;
 $description = $item->getElementsByTagName('description')->item(0)->firstChild->nodeValue;
 $pubDate = $item->getElementsByTagName('pubDate')->item(0)->firstChild->nodeValue;
 $guid = $item->getElementsByTagName('guid')->item(0)->firstChild->nodeValue;

 $json['item'][$key]['title'] = $title;
 $json['item'][$key]['description'] = $description;
 $json['item'][$key]['pubdate'] = $pubDate;
 $json['item'][$key]['guid'] = $guid; 
 }

echo json_encode($json);

Retrieve all links from a html page/file with PHP

 

$html = file_get_contents('path/to/file.html');
// Create a new DOM document
$dom = new DOMDocument;

// Parse the HTML. Use the @ to avoid any parsing errors if the $html string isn't valid XHTML
@$dom->loadHTML($html);

// Get all links 'a' we can use also 'img', 'li, 'table', etc to extract other tags.
$links = $dom->getElementsByTagName('a');

foreach ($links as $link){
    echo $link->nodeValue;
    // Full node
    echo $link->getAttribute('href'), '<br />';
    // the link itself
}