Jump to content

Recommended Posts

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  :shrug:

 

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

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.

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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.