domain matching regex

A regular expression that validates a given domain without its top level domain. I didnt need to validate the tld because this comes from a selectbox, so its predefined and always valid. The http protocol or the second level domain www. are both optional, it can be written or not.

$regex = "/^(?:(http:\/\/)?)(?:(w{3}\.)?)([A-Z0-9\-".utf8_encode("äÄöÖüÜ")."]{3,})$/i";
if(!preg_match($regex,$domainname)) {
	return false;
}

So the string can look like this:
http://www.liquidbass or www.liquidbass or http://liquidbass

detailed Description:

/^

This is the beginning of the regex. The ^ is used for searching all matches from the beginning of the given string.

(?:(http:\/\/)?)(?:(w{3}\.)?)

Here we have the optional protocol and the optional second level domain www. …

([A-Z0-9\-".utf8_encode("äÄöÖüÜ")."]{3,})

This part of the regex allows all characters from a to z, hyphens and all numerics from 0 to 9.
Additionally german special chars are allowed too.
All these possible characters must match a stringlength of minimum 3.

$/i

the dollar stands for the strings end, so it would be searched for matches from beginning to the end.
the /i stands for case sensivity – the given string can be in capital letters or in lowercase.

Telefonnummern Routing-Problem

Unser geschäftlicher ISDN Telefonanschluss kann von diversen Anrufern nicht erreicht werden, derjenige erhält entweder ein Besetztzeichen, oder sofern er vom Mobiltelefon aus anruft die Information dass Netz sei belegt.

Bei den Telefonanbietern ist dieses Problem bekannt, scheinbar wird aber nicht gerne darüber mit dem Kunden gesprochen oder diskutiert – Bereits vor unserem Wechsel des Telekommunikationsanbieters Arcor AG zur deutschen Telekom AG trat dieses Phänomen vereinzelt auf, allerdings in einem noch erträglichen Maße.

Es scheint irgendwo ein Routingproblem zu geben, über das man uns leider nicht so recht aufklären will oder kann. Nach unserer Rufnummernübernahme von Arcor zur deutschen Telekom tritt dieses Problem nun so massiv auf, dass wir die nicht durchkommenden Anrufer sehr schnell selektieren konnten. Es handelt sich dabei immer um Anschlüsse von externen Anbietern.

Erste Gespräche mit dem jetzigen Anbieter verliefen erfolglos, Providerseitige Tests waren fehlerfrei, wären wir dennoch der Meinung es bestünde ein Problem so müsse jemand vorbeikommen und das wird dann natürlich berechnet.

Nach dem das Auswechseln der Telefonanlage wie bereits erwartet keine Besserung brachte versuchten wir es wieder bei dem Provider. Diesmal kannte man plötzlich das Problem, wies es aber typischerweise weit von sich. Es kann wohl sehr lange dauern bis dieses Problem behoben ist, denn Arcor lässt nicht mit sich reden, so hieß es. Wir sollten also selbst Arcor ein wenig anstoßen.

Ein Anruf bei Arcor verlief wie erwartet. Man wusste nichts mit unserem Anruf anzufangen und sagte es uns das dies das falsche Vorgehen sei.

Wir bekommen deutlich weniger Anfragen von potenziellen Neukunden und generell klingelt das Telefon deutlich seltener.

truncate text-strings without cutting words

This is an easy way to truncate strings without cutting words after n characters.

bad one:
Lorem ipsum dolor sit amet, hy…

good one:
Lorem ipsum dolor sit amet, hymenaeos …

$string = "Lorem ipsum dolor sit amet, pellentesque wisi ut congue eget quam.";
$strLength = 30;
echo substr ( $string, 0, strrpos ( $string, ' ', - ( strlen ( $string ) - $strLength ) ) );

Webhostingday 2009

Die diesjährigen Webhostingdays fanden vom 18. bis 20. März bei Köln in Brühl auf dem Gelände des Phantasialands statt. Hier trafen sich etwa 2000 interessierte Besucher aus der ganzen Welt die sich innovative Produkte und Dienstleistungen vorstellen ließen, sich die spannenden Vorträge der Unternehmen aus der Hosting- und IT-Branche anhörten, sich untereinander austauschten und nebenbei Achterbahn fahren konnten. Zum abschließenden Höhepunkt gab es die sogenannte ConneXion Party mit einem wunderbaren Menü-Programm.

Ein sehr gelungenes Event – Wir freuen uns bereits auf das nächste Jahr!

set multilingual pageTitle in a view or element

I have searched for a long time until i found the reason why i couldnt make a pageTitle multilingual in a view or in an element.

First I tried to edit the title in this way and became unhappy because it was written in the content area of my page and not in the titletag.

$this->pageTitle = __('new PageTitle');

The second parameter “true” will avoid displaying the text directly.

$this->pageTitle = __('new PageTitle', true);

So, when you write it in this way, it works!

Installing Prototype/Scriptaculous into your CakePHP App

I wanted to install the prototype framework with the scriptaculous effects to my cakePHP Application, but after uploading the prototype files into the webroot/js folder and linking them in the layout, i got a failure message like “Undefined variable: javascript”.

This variable has to be defined in the Applications Helper, so you can put this line of code in your AppHelper class. If you dont know what to do: create a file named “app_helper.php” in your /app folder and insert these lines of code.

class AppHelper extends Helper {
	var $helpers = array('Html','Javascript','Ajax');
}

The $javascript variable is now available and you can insert your javascript files (the prototype framework in my excample) like this in the head of your layout.

		echo $javascript->link('scriptaculous/lib/prototype');
		echo $javascript->link('scriptaculous/src/scriptaculous');

		// Scripts from a view
		echo $scripts_for_layout;

Removing folders content except specific files or subfolders

I often need to remove files or folders in a dierctory – but I also often must not delete the whole directory, so here is the shell syntax for removing everything from a directory excepting your searchparameter.

This removes all files and subfolders in your current folder, excepting the cgi-bin directory.

ls | grep -v cgi-bin | xargs rm -R

search a string within a gzip file

You can search within possibly compressed files for a regular expression.
This helps me searching for strings in old compressed logfiles.

zgrep [ grep_options ] [ -e ] pattern filename…

This greps “searchstring” (without case sensitivity) from the compressed file in filename.gz
and writes the results to a new file with the name Result.

zgrep -i 'searchstring' ./filename.gz > ./Result

This greps the same string like in the example above, but with the difference that its not just parsing one file, its searching for the string within all gzip files in this directory and its only writing the filename where the searchstring is found to the new Result file.

zgrep -il 'searchString' ./*.gz > ./Result

extracting specific files from a tarball

If you have a big tarball and you dont want to extract all files and folders of it, you can use grep to extract only specific files or folders.

tar xfvkp Backup_23-06-07.tar.gz $(tar tf Backup_23-06-07.tar.gz | grep 'mySpecific/Folder')