Reguläre Ausdrücke in PHP
Anhand dieses RegEx wird die Benutzung der Operatoren | und * demonstriert.
<?php
/*
* Created on 21.02.2006
* @autor Michael Peuss
*/
/**
* Folgender regulärer Ausdruck erkennt Wörter,
* die nur aus 'a's und 'b's bestehen
*/
$regEx = '(a|b)*'; // oder [ab]*
$regEx = '^'.$regEx.'$';
// Gueltige Woerter:
$sprache = array();
$sprache[] = '';
$sprache[] = 'a';
$sprache[] = 'b';
$sprache[] = 'aa';
$sprache[] = 'bb';
$sprache[] = 'ab';
$sprache[] = 'ba';
$sprache[] = 'aba';
$sprache[] = 'bab';
$sprache[] = 'baa';
$sprache[] = 'abb';
foreach ($sprache as $wort) {
if(!ereg($regEx, $wort)) {
die('nicht erkanntes Wort: '.$wort);
}
}
// Ungueltige Woerter:
$sprache = array();
$sprache[] = 'A';
$sprache[] = 'B';
$sprache[] = 'aA';
$sprache[] = 'aB';
$sprache[] = ')';
$sprache[] = '1';
$sprache[] = 'c';
$sprache[] = ' ';
$sprache[] = 'a a';
foreach ($sprache as $wort) {
if(ereg($regEx, $wort)) {
die('erkanntes Wort: '.$wort);
}
}
echo 'RegEx ok!';
?>
|
Neue Beiräge auf Homepage-Werbung.de
Mit aktuellen Beiträgen Traffic von einer Homepage auf die andere lotsen
Ein paar Links fürs Grundverständnis zum Thema ‘Steuern’
Outsourcing – wohin mit der Arbeit?
RSS Newsfeed auf Homepages einbinden (Tutorial)
Kostenlose Leseprobe ‘Website Boosting’ Magazin
Satelliten Projekte (SEO-Taktik)
OVK Online-Report 2010/01 veröffentlicht (Linktipp)
Ad Management Plugins, Tutorials, Infos… (Linktipp)
Blogposts mit ‘RF Twitter Post’ (Wordpress Plugin) automatisch bekannt machen
7 Social Bookmarking Dienste im Vergleich
|