Fwrite a specific string under a specified string

Discussion in 'PHP' started by andytan91, Aug 16, 2010.

  1. #1
    Hello guys i am trying to figure out how to fwrite a string for example "Recommended Settings for Service Pack" under "Current Settings for Service Pack: 5.1.2600ServicePack3Build2600". I figure i cant use line number as an argument because the file report may be dynamic so i will need to use Current Settings as an argument. Please guide me if you have any ideas..thanks:) !

    auditreport
    table
    ServicePackSetting
    Service Pack Requirement: Fail
    Current Settings for Service Pack: 5.1.2600ServicePack3Build2600
    MajorAuditandAccountPolicies
    Maximum Password Age Requirement: Fail
    Current Settings for Maximum Password Age Requirement: 42
    Minimum Password Length: Fail
    Current Settings for Minimum Password Length Requirement: 0
     
    andytan91, Aug 16, 2010 IP
  2. jpratama

    jpratama Member

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    How about to use string_replace() function ? Maybe something like :
    str_replace ($string , "Current Settings for Service Pack: 5.1.2600ServicePack3Build2600" , "Current Settings for Service Pack: 5.1.2600ServicePack3Build2600\nRecommended Settings for Service Pack");
    PHP:
     
    jpratama, Aug 16, 2010 IP
  3. andytan91

    andytan91 Greenhorn

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    thanks for the suggestion..eventually i used preg_replace heh...however i have met a problem here, the strings after Service Pack: are dynamic and thus i cant hardcode " 5.1.2600ServicePack2Build2600" in the replacement array..so how can i pass Example Current Settings stated below into the replacement array?

    Example Current Settings
    "Current Settings for Service Pack: 5.1.2600ServicePack2Build2600"


    foreach($lines as $line)
    {
    $string1 = $line;
    $patterns = array();
    $patterns[0] = '/\bCurrent Settings for Service Pack:.*\b/';
    $replacements = array();
    $replacements[0] = "Current Settings for Service Pack: 5.1.2600ServicePack2Build2600 
    Recommended Settings for Service Pack: $servicepack";
    $string1 = preg_replace($patterns , $replacements , $str
    PHP:
     
    andytan91, Aug 16, 2010 IP