Jump to content

Regular Expressions halp


andytan91

Recommended Posts

Hello guys basically i am doing an edit policy function which uses the power of regular expression(preg_replace). But i have a problem here. The below is the text output from the DOS command whereby i will need to edit the START_TYPE of the following services. My question is how to make preg_replace to differentiate the START_TYPE that belongs to each service??

 

START_TYPE:DISABLED

DISPLAY_NAME:Alerter

START_TYPE:AUTO_START

DISPLAY_NAME:AutomaticUpdates

START_TYPE:DEMAND_START

DISPLAY_NAME:BackgroundIntelligentTransferService

START_TYPE:DISABLED

DISPLAY_NAME:ClipBook

 

 

 

Link to comment
Share on other sites

regex not necessary

 

$file = file('test.txt');
$c = 0;
foreach ($file as $row) {
  $row = explode(':',trim($row));
  $list[floor($c)][$row[0]] = $row[1];
  $c += .5;
}
echo "<pre>";
print_r($list);

 

[pre]

Array

(

    [0] => Array

        (

            [sTART_TYPE] => DISABLED

            [DISPLAY_NAME] => Alerter

        )

 

    [1] => Array

        (

            [sTART_TYPE] => AUTO_START

            [DISPLAY_NAME] => AutomaticUpdates

        )

 

    [2] => Array

        (

            [sTART_TYPE] => DEMAND_START

            [DISPLAY_NAME] => BackgroundIntelligentTransferService

        )

 

    [3] => Array

        (

            [sTART_TYPE] => DISABLED

            [DISPLAY_NAME] => ClipBook

        )

 

)

[/pre]

Link to comment
Share on other sites

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.