xDimitrii Posted July 15, 2011 Share Posted July 15, 2011 Hello everybody, I'm trying to make a small website for my server, where you can see all the running processes and where you can kill them. The only problem is that it doesn't work I want to split every rule of the textfile in 2 parts (name and path), to put these 2 in a separate cell. I wanted to do this with a substring, so that he splits the rule at the position where C:\ is located. To find the location of C:\, I wanted to use the strpos() function. But after hours of trying I still have no result..... The only thing that gave a result is when I manually added a rule in the $line_of_text variable. But php doesn't want to do the strpos() function when the $line_of_text variable is filled by the textfile. Anyway, here is my code: if(isset($_POST['shutdown_x'])){ shell_exec("C:\\Windows\\System32\\cmd.exe /c wmic /output:C:\process.txt process get description,executablepath"); $file_handle = fopen("c:\\process.txt", "r"); while (!feof($file_handle)) { $line_of_text = fgets($file_handle); $findme = "C:\\"; $pos = strrpos($line_of_text, $findme); echo("Line of text: ".$line_of_text."<br />"); echo("Type: ".gettype($line_of_text)."<br />"); echo("Find: ".$findme."<br />"); echo("Position: ".$pos."<br />"); echo("Speciale zoekfunctie: ".stristr($line_of_text, 'C:')); echo("<br /><hr />"); } fclose($file_handle); } ?> This is the textfile, which is created by the dos-command: csrss.exe C:\windows\system32\csrss.exe wininit.exe C:\windows\system32\wininit.exe csrss.exe C:\windows\system32\csrss.exe services.exe C:\windows\system32\services.exe lsass.exe C:\windows\system32\lsass.exe lsm.exe C:\windows\system32\lsm.exe winlogon.exe C:\windows\system32\winlogon.exe svchost.exe C:\windows\system32\svchost.exe AtService.exe c:\Program Files\Fingerprint Sensor\AtService.exe svchost.exe C:\windows\system32\svchost.exe svchost.exe C:\windows\System32\svchost.exe svchost.exe C:\windows\System32\svchost.exe svchost.exe C:\windows\system32\svchost.exe And this is the output that I get: Line of text: mysqld.exe c:\xampp\mysql\bin\mysqld.exe Type: string Find: C:\ Position: Speciale zoekfunctie: Link to comment https://forums.phpfreaks.com/topic/242050-split-string-from-textfile-with-strpos/ Share on other sites More sharing options...
xDimitrii Posted July 19, 2011 Author Share Posted July 19, 2011 Nobody? Link to comment https://forums.phpfreaks.com/topic/242050-split-string-from-textfile-with-strpos/#findComment-1244480 Share on other sites More sharing options...
WebStyles Posted July 19, 2011 Share Posted July 19, 2011 you can use explode to separate each line... something like: $file = file_get_contents('yourFileName.txt'); $lines = explode("\n",$file); foreach($lines as $line){ $parts = explode("C:",$line); echo '<br \>C:'.$parts[1]; } hope that helps. Link to comment https://forums.phpfreaks.com/topic/242050-split-string-from-textfile-with-strpos/#findComment-1244538 Share on other sites More sharing options...
cyberRobot Posted July 19, 2011 Share Posted July 19, 2011 The code works fine for me, here is part of the output: Line of text: svchost.exe C:\windows\system32\svchost.exe Type: string Find: C:\ Position: 29 Speciale zoekfunctie: C:\windows\system32\svchost.exe -------------------------------------------------------------------------------- Line of text: AtService.exe c:\Program Files\Fingerprint Sensor\AtService.exe Type: string Find: C:\ Position: Speciale zoekfunctie: c:\Program Files\Fingerprint Sensor\AtService.exe -------------------------------------------------------------------------------- Line of text: svchost.exe C:\windows\system32\svchost.exe Type: string Find: C:\ Position: 29 Speciale zoekfunctie: C:\windows\system32\svchost.exe My text file contained exactly what you mentioned in the original post. I processed the text file with your same code...except I removed the shell_exec() part and modified the fopen(). Here is the code I used: <?php $file_handle = fopen("process.txt", "r"); while(!feof($file_handle)) { $line_of_text = fgets($file_handle); $findme = "C:\\"; $pos = strrpos($line_of_text, $findme); echo("Line of text: ".$line_of_text."<br />"); echo("Type: ".gettype($line_of_text)."<br />"); echo("Find: ".$findme."<br />"); echo("Position: ".$pos."<br />"); echo("Speciale zoekfunctie: ".stristr($line_of_text, 'C:')); echo("<br /><hr />"); } fclose($file_handle); ?> Link to comment https://forums.phpfreaks.com/topic/242050-split-string-from-textfile-with-strpos/#findComment-1244577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.