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.

[PHP/RegEx] Space Zählen

Empfohlene Antworten

Veröffentlicht

Hi,

ich hab die Ehere und darf einen Dateibaum generieren.

Meine Quelldaten sind so gemacht, das Unterordner ein Space mehr vorrangestellt haben als der Ordner in dem ise sich befinden:


firefox/

 nummerZwei.txt

 profiles.ini

 pluginreg.dat

 8nm3l3bk.default/

  search.rdf

  localstore.rdf

  bookmarks.bak

  defaults.ini

  mimeTypes.rdf

  compatibility.ini

  US/

   bookmarks.html

  lock

  prefs.js

  bookmarks.html

  xpti.dat

  formhistory.dat

ich bastel das hin und her, aber mein eignetliches Problem:

Wie muss mein RegEx aussehen, damit ich ein preg_match(_all) machen kann um die anführenden Spaces zu zählen?

Gibts vllt noch andere möglichkeiten?

Mein aktueller RegEx sieht so aus:

preg_match_all("/(\s+$)/",...

aber das funzt irgendwie nich, ich bekomm da immer verschachtelte Arrays zurück.

array1( 1 => Name, 2 => array( 1 => Name, 2 => array( 1 => Name), 3 => name) 3=> Name);

array2 (1 => Name2, 2=> array( 1 => Name2 ...

preg_match_all("/(\s+$)/",...

Habe ich Dich richtig verstanden? -->


foreach ($dirlistArr as $key=>$val) {

  if (preg_match("/^( *)(.*)$/",$val,$pregRes)) {

    $anzahlSpaces = strlen($pregRes[1]);

    echo "Die Datei ".$pregRes[2]." hat ".$anzahlSpaces." Spaces im Dateinamen. ";

  }

}

DANKE!

also dein RegEx funktioniert super!

Allerdings mach ich das ganze mit preg_match_all da preg_match, soweit ich de.php.net verstnadne hab, nur bis zum ersten fundsucht und dann abbricht.

im großen und ganzen siehts nu so aus:


$handle = fopen($filename, "r");
while($line = fgets($handle)){
preg_match_all("/^( *)(.*)$/",$line, $actspaces);
$linedepth = strlen($actspaces[1][0]);
#Verarbeitung der Daten
}
[/php]

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.