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.

Empfohlene Antworten

Veröffentlicht

Hallo,

ich möchte gerne eine Textdatei einlesen die wie folgt aussieht:

0 1 Normal_ij 64 0.00000600

0 1 Normal_ij 128 0.00001800

0 1 Normal_ij 128 0.00001800

Nun soll nicht zeilenweise eingelesen werden sonder wort weiße in ein array.

Grund ich will das in einen Graphen abbilden (Wort 4-5, x-y)

Es scheitert nur daran das ich nicht weiß wie ich die werte bekomme

am besten wäre ein zwei dimesionales array. für [zeile][wort]

Danke schonmal für Tipps oder Lösungen.

Erst wirfst du einen Blick in die PHP-Dokumentation, siehst von etwaigen Versuchen ab, dir eine perfekte Lösung vorkauen zu lassen, beschäftigst dich mit dem zuvor gelesenen und entwirfst einen Lösungsansatz. Im Fall, dass du das Problem nicht selbst komplett lösen kannst, kommst du anschließend mit deinem Entwurf wieder und wir gucken zusammen drüber.

Merke: "Macht mal" ist nicht drin.

  • Autor

<?php


$handle = fopen ("addMatMat/00_addMatMat_01_Normal_ij.dat", "r");


while ( $inhalt = fgets ($handle, 4096 ))

{

  echo "$inhalt ";

}

 echo "</br> gf";

fclose($handle);


$teile = explode(" ", $inhalt);

echo $teile[0]; // Teil1

echo $teile[1]; // Teil2



?>

Ungetestet da keine Zeit (hab eben in 5 min nur schnell ein paar Gedanken als Code notiert!).

Zitat :"Danke schonmal für Tipps oder Lösungen. "

Wer nichts lernt ist auch keine Konkurrenz ;)!, Mal ein bischen mehr Eigeninitiative an den Tag legen ;) !

Tip! Teile dein Gesamtproblem in einzelne Schritte/Komponenten auf!

Hier am Beispiel :

1. An den Inhalt kommen .....

2. Option 1: Zeilenweise einlesen Option 2: ....

3. Wörter aus Zeile extrahieren

usw. usf.

So kannst Du dich auf einzelne Probleme fokussieren!

1. Wie lese ich eine Datei ein

2. Wie splitte ich Strings

usw. usf.


/*

 * returns null or array

 */

function FileTo2DArray($fname) 

{

	$content = file_get_contents ($fname);


	$result  = null;


	if($content)

	{	

		$result = array();


		$rows = explode('\n',$content);


		foreach($rows as $row)

		{

			$result[]=explode(' ',$row);

		}

	}


	return $result;

}



/*

 * returns null or array

 */

function FileTo2DArray($fname) 

{	

	$fh = fopen($fname,"r");


	$result  = null;


	if($fh)

	{	

		$result = array();


		while(!feof($fh))

		{

			$row = fgets($fh);


			if($row)

			{

				$result[]=explode(' ',$row);

			}

		}


		fclose($fh);

	}	


	return $result;

}



Bearbeitet von Patrick_C64

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.