Reguläre Ausdrücke und CSS3
Redaktionelle Einordnung
Diese archivierte Diskussion behandelt Reguläre Ausdrücke und CSS3 aus Sicht der Rubrik PHP & MySQL.
CMS- und Technikfragen sind heute besonders dann relevant, wenn sie Indexierung, Rendering, interne Verlinkung oder Relaunch-Risiken beeinflussen.
Sinnvoll nutzbar bleibt der Thread vor allem als historischer Kontext, für typische Fragestellungen und zur Einordnung älterer Empfehlungen.
Einige im historischen Thread genannte Tools, Dienste oder externe Links könnten heute nicht mehr verfügbar oder inhaltlich überholt sein. Nutzen Sie sie bitte nur mit zusätzlicher Prüfung.
Startbeitrag
Originaler Foreninhalt in modernisierter Darstellung.
Mein alter Feind... Reguläre Ausdrücke...
Ich versuche, mit folgendem als Beispiel, die CSS3 Media/ Page rauszufiltern, damit ich sie später verarbeiten kann:
[css]
@media screen only (width: 200) and (heigh: 200) {
.test1 { color: red; }
.test2 { color: red; background-color: green; }
#test1 { color: black; background-color: white; }
#test2 { color: yellow; background-color: black; }
}
@media screen only (width: 300) and (heigh: 300) {
.test1 { font-size: 10px; }
.test2 { font-size: 20px; color: red; background-color: green; }
#test1 { font-size: 30px; color: black; background-color: white; }
#test2 { font-size: 40px; color: yellow; background-color: black; }
}
@page {
.test1 { font-size: 10px; }
.test2 { font-size: 20px; color: red; background-color: green; }
#test1 { font-size: 30px; color: black; background-color: white; }
#test2 { font-size: 40px; color: yellow; background-color: black; }
}
.test1 { font-size: 1em; }
.test2 { font-size: 2em; color: red; background-color: green; }
#test1 { font-size: 3em; color: black; background-color: white; }
#test2 { font-size: 4em; color: yellow; background-color: black; }
[/css]
Ich benötige das @...(...) {...}
Leider führen alle Ansätze bis jetzt nicht zum Erfolg...
Antworten
4 BeiträgeHallo
Vielleicht solltest du mal ganz genau erklären was du genau vorhast.
Zuerst kannst du dir ja die Treffer so holen von dem was du nicht haben möchtest. <?php
preg_match_all(\'#@page\\s*\\{.*\\}/s*}#su\',$text,$treffer)
?>
Und das dann halt eben mit <?php rauswerfen.
if (count($treffer) > 0){
str_replace($treffer,\'\',$text);
}
?>
Unter Umständen wäre auch folgende Funktion hilfreich wenn man von einem Array mit den media Typen ausgeht.
de2.php.net/manual/de/function.preg-grep.php
Zumindest sollte man die Höhe auch richtig schreiben sonst wird das CSS mässig nicht richtig umgesetzt.
Gruß
Jörg
Der folgende Ausdruck liefert mir das benötigte... fast: <?php
$string = "@media screen only (width: 200) and (heigh: 200) {
.test1 { color: red; }
.test2 { color: red; background-color: green; }
#test1 { color: black; background-color: white; }
#test2 { color: yellow; background-color: black; }
}
@media screen only (width: 300) and (heigh: 300) {
.test1 { font-size: 10px; }
.test2 { font-size: 20px; color: red; background-color: green; }
#test1 { font-size: 30px; color: black; background-color: white; }
#test2 { font-size: 40px; color: yellow; background-color: black; }
}
@page {
.test1 { font-size: 10px; }
.test2 { font-size: 20px; color: red; background-color: green; }
#test1 { font-size: 30px; color: black; background-color: white; }
#test2 { font-size: 40px; color: yellow; background-color: black; }
}
.test1 { font-size: 1em; }
.test2 { font-size: 2em; color: red; background-color: green; }
#test1 { font-size: 3em; color: black; background-color: white; }
#test2 { font-size: 4em; color: yellow; background-color: black; }";
$regex = "/(@media|@page)(.*?)\\{(.*?)\\}/is";
preg_match_all ($regex, $string, $output, PREG_SET_ORDER);
?>
Herauskommt: Array
(
[0] => Array
(
[0] => @media screen only (width: 200) and (heigh: 200) {
.test1 { color: red; }
[1] => @media
[2] => screen only (width: 200) and (heigh: 200)
[3] =>
.test1 { color: red;
)
[1] => Array
(
[0] => @media screen only (width: 300) and (heigh: 300) {
.test1 { font-size: 10px; }
[1] => @media
[2] => screen only (width: 300) and (heigh: 300)
[3] =>
.test1 { font-size: 10px;
)
[2] => Array
(
[0] => @page {
.test1 { font-size: 10px; }
[1] => @page
[2] =>
[3] =>
.test1 { font-size: 10px;
)
)
Es werden mir das nach @ geliefert, der Inhalt bis zur Klammer und die erste Definition dess CSS, die restlichen werden nicht angezeigt.
Hallo
Kann so auch nicht funktionieren. Da fehlt einfach noch was von der Logik her. <?php
$regex = "/(@media|@page)(.*?)\\{(.*?)\\}\\s*\\}/is";
?>
sollte dann für die restlichen CSS Anweisungen sorgen.
Nur die CSS Anweisungen die nicht in so einem Block stecken werden dabei noch nicht berücksichtigt.
Aber mir ist immer noch nicht klar worauf das Ganze überhaupt hinauslaufen soll.
Deshalb kann ich hier echt nur raten worauf du überhaupt hinaus willst.
Gruß
Jörg
Danke.
Ich schreibe ein eignes Minify System, was die CSS3 kompatibel ist und die dopplungen con den CSS Styles entfernt.