Powered by Cellfex RSS Follow me on Spotify

Archive for the ‘php’ Category

While setting up cronjob for php script got (dont forget to php -l you r script btw) unexpected “<b>Parse error</b>:  syntax error, unexpected T_OBJECT_OPERATOR”

D’oh. appearantly CLI for PHP is not always php5. beware.

10 May 2011

Oh this unexpected T_OBJECT_OPERATOR

Author: Edgars | Filed under: DailyStuff, php, serversandstuff

Once and for all.

$_SERVER['REDIRECT_URL'] is dead in PHP. Use $_SERVER['REQUEST_URI'] instead.

Dont know which PHP version and configuration depreciates REDIRECT_URL, but afaik its old as dinosaur and comes from HTTP_SERVER_VARS superglobal. so obviously times change and caravan moves on.

4 Jan 2011

R.i.p REDIRECT_URL long live REQUEST_URI

Author: Edgars | Filed under: Web Development, php

Ten years ago i thought that shorthand if statements was a cool thing. on one hand it improved readability and on other hand it was short and simple one line. Read the rest of this entry »

17 Aug 2010

Cool guys don’t use shorthand statements

Author: Edgars | Filed under: Web Development, php

While using PHPUnit i noticed that my test “image resource” folder couldnt be accessed even thought that it was located ../../resources/images. Not too far away if script is called directly.
PHP’s file_get_contents() and file_put_contents() have a neat attribute called use_include_path that allows from PHP5 to include a common php include path.
On the other hand – unlink(), touch() and other oldsk00l functions dont use include path, so i was in trouble since PHPUnit test case and suite use PHPUnit’s plugin folder on zend/eclipse. It means that there is almost no goddamnway to figure out how to access the folder _relatively_ two levels down if you are located somewhere else in server file tree. Read the rest of this entry »

13 Jul 2010

Folder/directory path manipulation in PHP

Author: Edgars | Filed under: Web Development, php

There are times when provider changes server and doesnt put everything back as it was before. Mostly this concerns PHP error reporting settings.
Of course, in old days nobody took a good care of proper coding so often $array[key] was used instead of $array['key'] and this is just one of the smallest things around.

I promise to write later a basic guide for avoiding common PHP error stuff like inproper use of quotes, also inside regular expressions (shame on you TCPDF, have you ever thought of checking your code with notices turned on? Read the rest of this entry »

9 Jul 2010

Centralizing PHP error reporting via .htaccess

Author: Edgars | Filed under: Web Development, php

I had to enter couple of millions of dummy text entries (with titles and contents) in a database so i created this small PHP script that takes latin letters and sort them out in words. It has some properties to adjust and also a definition of letters and punctuation used. I KNOW, its not perfect but I just wanted to make something automatic, not perfect tool and still it will suite you fine if you want to generate vast amounts of dummy text or just are tired of loripsuming.
function generateDummyText($textLength, $sentenceMinLength, $sentenceMaxLength, $wordMinLength, $wordMaxLength) {
$textOutput = '';
$textCounter = 0;
$letters = 'abcdefghijklmnoprstuvwxyz';
$punctuation = '.!?';
while ($textCounter<$textLength) { $sentenceLength = rand($sentenceMinLength, $sentenceMaxLength); $firstWord = true; $firstLetter = true; for ($sentenceCounter = $sentenceLength; $sentenceCounter>0; $sentenceCounter--) {
if ($firstWord==false) {
$textOutput .= (rand(0,10)==0) ? ', ' : ' ';
}
$wordLength = rand($wordMinLength, $wordMaxLength);
for ($wordCounter = $wordLength; $wordCounter>0; $wordCounter--) {
$letter = $letters[rand(0,(strlen($letters)-1))];
if ($firstLetter==false) {
$textOutput .= $letter;
} else {
$textOutput .= strtoupper($letter);
$firstLetter = false;
}
$textCounter++;
}
$firstWord=false;
}
$textOutput .= $punctuation[rand(0,(strlen($punctuation)-1))].' ';
}
return trim($textOutput);
}

Attributes are pretty selfexplainable, but anyway, here is an example.
$textLength=3000;
$wordMinLength = 3;
$wordMaxLength = 7;
$sentenceMinLength = 20;
$sentenceMaxLength = 100;

feel free to update, change, upgrade, improve or whatever. cheers!

23 Apr 2010

PHP dummy text generator

Author: Edgars | Filed under: Web Development, php