Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Regex funktioniert in PHP nicht

Empfohlene Antworten

Veröffentlicht

Hallo,

ich wollte ein kleines Programm schreiben, das mir die Namen für ein assoziatives Array zurückliefert. Also die Namen, mit dem ich das Array anspreche. Z. B.

$satz[id]

Anders ausgedrückt: Ich weiß die Namen nicht, brauche sie aber.

Ich habe mir dazu folgenden Regulären Ausdruck ausgedacht:


\[.+\]

Es muss also die öffnende eckige Klammer, mindestens ein beliebiges Zeichen und die schließende eckige Klammer kommen.

Das Code Snippet dazu sieht bis jetzt so aus:


$print = print_r($satz, true);
// Nach Namen der Spalten spliten
$satzsplit[] = preg_split("\[.+\]", $print);
foreach ($satzsplit as $strname) {
// Klammer auf und Klammer zu herausfiltern
$name = substr($strname, 1, strlen($strname) - 1);
// tue irgendwas
}
[/PHP]

Leider funktioniert es (noch) nicht. Ich habe schon danach gegoogelt. Es hieß, ich solle am Anfang und am Ende einen Slash machen (/). Wenn ich das tue, kommt zwar keine Fehlermeldung mehr, aber es liefert mir auch nicht das zurück, was ich wollte.

MFG derwunner

Mach es dir doch nich so kompliziert und deklarier den Namen der Variable seperat und danach erst weißt

du sie dem Array zu.



$array_name = 'satz';

${$array_name} = array( 'id1' => 'asd1',
'id2' => 'asd2',
'id3' => 'asd3',
'id4' => 'asd4');

foreach($arr as $key => $value) {

echo $array_name.'['.$key.']'."\r\n";

}

[/PHP]

Bearbeitet von ins0

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.