Quickly recreate SQLite database structure
Here you’ll find an example (and some tips) of an extremely easy PHP code for recreating SQLite database. It can also be used to execute any SQLite query (or serie of queries) stored in a external file.
Here you’ll find an example (and some tips) of an extremely easy PHP code for recreating SQLite database. It can also be used to execute any SQLite query (or serie of queries) stored in a external file.
If you’re still lurking in the darkness of writing code with pure PHP and not using any framework then in this post you can find some nifty function, useful for drawing a HTML list boxes.
Basically it tries to render (draw) a <select>
element basing on input data provided in $source
variable. It can be either a list (key=>value) or string, where values and items’ texts are separated with delimiter. Such string can be provided directly or read from file. In this case you only provide path to a file (source of data).
Read More “Simple function for drawing HTML dropdown list from various sources”
I wanted to prove myself, that writing WordPress plugins isn’t very hard task. Or, actually, that this can be really, really easy. So I came with this example. This is as simple as possible plugin example. It currently does nothing else except for locking entire front-end of your site for not registered users.
I was faced with a problem of picking a good photo manipulation library. Either client-side or server-side. Both for working with my newest Yii project. This article is a summary of my quick research in this field.
All JavaScript libraries works on Canvas, so require HTML5 and Canvas-enabled browsers. Most modern browsers supports both of them in newest versions.
The only PHP image manipulation library works mostly on uploaded image.
Yesterday I took a part in interview for PHP developer position. My interview task was to solve fifteen questions in quite simple test. One of the questions was to decide if given code sample be treated as unsafe and in which conditions.
I gave a wrong (as it turned out) answer and the argumentation from the intervieerw was quite surprising for me in the first time. Finally I realized my mistake.
Read More “When PHP code should really be treated as unsafe”
In Yii main application is actually a module (core one) so each module configuration actually shares nearly everything what you can put to main application’s configuration file.
Thus, you can configure any Yii module, just as you would do with your main application. The only difference is that you don’t use external configuration file, but CModule::configure()
function instead.
Read More “Alternative module configuration that does not affect main configuration”
Out of this post I have extracted a simple function, that it is said to catch over 97% of mobile browsers available on any mobile devices, people are using in the world. Regular expression used inside detection function is so twixed, that I’m ready to believe, that this is true! :] Wanna give it a try on your mobile device? :>
By using five separate PHP functions, in correct order, you can easily pass (code and decode) entire page’s URL as a parameter of any other script call, redirect etc. And be sure that it will be read (decoded) correctly, no matter, how long your URL is or what kind of characters it is using.
You can encode any URL (current page, last visited page or any otherwise important) and pass it in another URL in the way that your user won’t notice that you’re actually passing an URL.
Presented solution can potentially be used as URL shortening service. Generated URLs aren’t that short (as maybe expected), but for really long URLs it does provides some shortening.
Read More “Passing current or last page full URL as a part of URL”
You can use CMarkdown class as typical Yii widget:
[code language=”php”]
<?php $this->beginWidget(‘CMarkdown’); ?>
_Markdown_ *example*
<?php $this->endWidget(); ?>
[/code]
or directly as a function:
[code language=”php”]
$text = ‘_Markdown_ *example*’;
$md = new CMarkdown;
echo $md->transform($text);
[/code]
That’s pretty much everything, folks!
Well saying “CMS” means a huge over-interpretation here. This article shows how to actually write the quickest and the simplest possible rich-text page content render for rendering Markdown-formatted texts stored in separate .txt
files.
The entire article is actually a single Yii action plus an example on how to call it.
Read More “The simplest possible CMS with CMarkdown and Yii”It turned out that in current version of Apache you’re limited to 255 characters at most between each pair od slashes (after URL decoding is done). This short article discusses this issue and maybe useful to all developers, who are dealing with “beauty” (SEO-optimized) URLs, like for example URLs to blog posts containing entire title inside.
This is a rare situation (255 characters limit between slashes, not for the entire URL), but still worth exploring.
This is a memo for me, to have all or at least most important and most common error codes, that can be returned by any socket-related function (socket_*) in PHP, handy in one single blog post.
PHP is the most popular programming language for development of webpages and web services. With addition of a good framework it can even produce a professional results. However, this does not change the fact, that it is also the most shitty programming language in the world, full of garbage and with number of stupidities beyond imagination. And professional programming (without a good framework) is impossible.
Even though this is a language of my choice (only after cleaning it from all the shit, by using a good framework), I decided to write this article, where I’m pointing out most annoying and stupid things, I ever found in PHP.
Notice, that I’m not talking here about things that some may see as wrong, while other will see as good. For example, I’m not talking about types auto-declaration and auto-change, which ones (mostly newbies) takes as ease of coding and others (mostly profs) as source of mess.
I’m talking here only about pure madness, confirmed piece of shit and horrible pain in the ass, this language is.
Please, take also into consideration that this text was written under strong emotional influence and thus it (intentionally!) contains a lot of harsh language and words or phrases that some readers may not accept.
Read More “Things for which I trully hate PHP and its creators”
So, there I was… needing to have any solution, that will allows me to write my very own port listener. Since the only language, in which I am handy is PHP, I was forced to be able to run PHP script without interruption, 24 hours a day, 7 days a week. That was a bit of challenge for me, given my quite very limited Linux knowledge, but — as they say — the only thing not possible in IT is to open an umbrella in your ass! :>
Read More “screen: Force program to continue after logging-off from the console”
Long long time ago in a galaxy far far away I wrote a very simple PHP script, that I usually put into index.php
of a directory, which contents I’d like to print out to the browser. I’m using this solutions on all servers and hostings which has Apache-based directory listings disabled and thus are showing empty page or error screen, if folder does not contain index.php
.
Here’s the code:
[code language=”php”]
$dir = getcwd();
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
echo(‘Files in this folder:<ul>’);
while (($file = readdir($dh)) !== false)
{
if ($file != ‘.’ && $file != ‘..’ && $file != ‘index.php’)
{
echo(‘<li><a href="’.$file.’">’.$file.'</a></li>’);
}
}
closedir($dh);
echo(”);
}
}
[/code]
That’s pretty much everything, folks!
The fastest way of generating passwords for htpasswd
program is… to use PHP for this task:
[code language=”php”]
$clearTextPassword = ‘some password’;
$password = crypt($clearTextPassword, base64_encode($clearTextPassword));
echo $password;
[/code]
You may also (of course!) use htpasswd
program or some 3rd party tools.
I was working on bigger project using PHP (Yii) and Oracle database (through PDO and Yii). This isn’t a very common combination and many developers thinks, that writing PHP application to use Oracle database is a pure madness, mostly due to many strange behaviors and nasty bugs, that are present in PDO driver for Oracle. I can actually confirm this. Following article contains links to my Yii forum discussions on various aspects of using Oracle with Yii and PHP. You may find it useful, if you’re struggling with any problem.
Regular expression was always a nightmare for me. Even though I understand how powerful these can be and I’m trying to use them in many places of my code, they’re still a huge mystery for me.
For this reason I have wrote a simple memo-article with a links to useful blogs, pages and tools for or about regular expressions.
Read More “Pages and tools on regular expressions”This article discusses using of ternary operator, a very usful yet not so famous, logic operator (if
counterpart) in Javascript, PHP and… Delphi. Alright, alright. Since Delphi sucks, it is only mentioned here.