Archive

Tag Archives: php

Some time ago I designed and implemented mobile solution to browse/search legal information actual in the Netherlands. There are a lot of legal institutions, rules, etc. in the Netherlands, so, the idea of application is to provide the roadmap for regular user to solve specified law question/problem.

There is a client-server solution. From one hand there is free android application which can be used as offline manual. As it’s mostly content oriented application, I created it by PhoneGap + HTML5 + jQueryMobile technology. But it’s not pure HTML5/JS/CSS solution because it needs several PhoneGap plugins implemented by Java.

Server side of the solution is a simple PHP+MySQL CMS implemented as single-page backbone.js web application to compose and correct the content of the manual. I also used Slim MVC, Twig templates and idiorm ORM to MySQL frameworks.

The workflow is:

  1. Content manager edits the content (CRUD) and deploy new version available via HTTP online;
  2. The clients automatically update (check, download and install) the latest version of content from that HTTP interface when they are online;
  3. Then the clients may use new content even offline.

There are also such useful features:

  • search by tags
  • feedback form
  • share the link/content via email/facebook/twitter/etc.

Image

Advertisements

If your XML has default name space like:
    <COLLADA xmlns=”http://www.collada.org/2005/11/COLLADASchema”></COLLADA&gt;
Then to use DOMXpath you should register this namespace with some prefix like:
    $xpath->registerNameSpace(‘dp’, ‘http://www.collada.org/2005/11/COLLADASchema&#8217;);
here ‘dp’ means default prefix;
Then use this prefix in your XPath query like:
    $nodes = $xpath->query(‘//fp:COLLADA’);

// real example
$DOMDocument = new DOMDocument;
$DOMDocument->strictErrorChecking = false;
//$sXml = ‘<COLLADA xmlns=”http://www.collada.org/2005/11/COLLADASchema”></COLLADA>&#8217;;
if (! $DOMDocument->loadXML($sXml))
    _error(“can’t parse XML”);

$xpath = new DOMXpath($DOMDocument);
$xpath->registerNameSpace(‘dp’, ‘http://www.collada.org/2005/11/COLLADASchema&#8217;);

foreach ($xpath->query(‘//dp:image/dp:init_from’) as $node)
{
    $node->nodeValue = $dir . “/model.jpg”;
}

$sXml = $DOMDocument->saveXML();

<?php

// XML/XSL: Transform one tag into another
// You need to have php_xsl.dll in your php extenstions

function transform($xml, $xsl) {
   $xslt = new XSLTProcessor();
   $xslt->importStylesheet(new SimpleXMLElement($xsl));
   return $xslt->transformToXml(new SimpleXMLElement($xml));
}

$sXml  = ‘<xml><sudhir><image id=”model_jpg” name=”model_jpg”>
  <init_from>models/cersi_ships/model.jpg</init_from>
  </image></sudhir></xml>’;

$sXsl  = ‘<xsl:stylesheet
    xmlns:xsl=”http://www.w3.org/1999/XSL/Transform&#8221; version=”1.0″>
    <xsl:output method=”xml”/>

    <xsl:template match=”image/init_from”>
        <init_from2><xsl:value-of select=”.”/></init_from2>
    </xsl:template>

    <xsl:template match=”* | @*”>
        <xsl:copy><xsl:copy-of select=”@*”/><xsl:apply-templates/></xsl:copy>
    </xsl:template>
   
</xsl:stylesheet>’;

echo transform($sXml, $sXsl);

Several weeks ago I’ve done simple PHP AJAX editor of dummy strings list. It was test task for the interview. There are list of strings saved in MySQL table and AJAX CRUD web interface.

The most fun point was a condition to avoid any JS or PHP framework. It means pure PHP and pure JS, as I understand, just to test coding skills. I realized that I’m using different frameworks for already long period of time. I can’t imagine myself coding without jQuery, for example. I remember those times but it was so long time ago…

Here is my implementation of example composed into single file: single_file.php

 

PHP function exit(int $status) uses numeric $status return code
but function exit(string $status) just outputs argument string.

The same is true for Python:

import sys
sys.exit(0)

and

imports sys
sys.exit(“aa! errors!”)

In Perl there is only exit(int_code) variant available. However, we use die(‘last words’) or even better Carp::confess() with stack back trace.

In Ruby we can call
exit(
fixnum=-1)
or Process.exit!(fixnum=-1) to exit immidiately
or abort("Message goes here")