Jump to content

Small Help


webstar

Recommended Posts

I'm trying to find the write coding to pull the First and Second words from the 2nd line and the entire 3rd line from this file and have them as $subject1 and $subject2  And I have no php background.

 

 

http://www.weatherserver.net/text/CWTO/WOCN11.txt

 

so $subject1 = WOCN11 CWTO

and $subject2 = SPECIAL WEATHER STATEMENT

 

 

Link to comment
https://forums.phpfreaks.com/topic/255096-small-help/
Share on other sites

<?php
$file_array = file('http://www.weatherserver.net/text/CWTO/WOCN11.txt');
$subject1_words = explode(" ",$file_array[2]);
$subject1 = $subject1_words[0] . " " . $subject1_words[1];
$subject2 = $file_array[3];

echo $subject1 . "<br />";
echo $subject2 . "<br />";
?>

 

Results:

WOCN11 CWTO

SPECIAL WEATHER STATEMENT

Link to comment
https://forums.phpfreaks.com/topic/255096-small-help/#findComment-1308020
Share on other sites

#!/usr/bin/php
<?php


# E-mail recipient(s).  Separate each address with a comma and a space.
$emailrecip = "removed";

# E-mail From name.
$emailfromname = "removed";

# E-mail From address.
$emailfromaddr = "removed";



$fp = fopen('php://stdin','r');
$data = "";
while(!feof($fp)) {
$new_data = fgets($fp,4096);
$data .= $new_data;
$data_array[$i++]=$new_data;
}
fclose($fp);
$patterns = array();
$patterns[0] = '/CWTO/';
$patterns[1] = '/CWWG/';
$patterns[2] = '/CWVR/';
$patterns[3] = '/CWHX/';
$patterns[4] = '/CWUL/';
$replacements = array();
$replacements[0] = '-ON-';
$replacements[1] = '-Prairies-';
$replacements[2] = '-BC-';
$replacements[3] = '-Maritimes-';
$replacements[4] = '-QC-';
$data_array = preg_replace($patterns, $replacements, $data_array);

$split_line = explode(' ', $data_array[2]);
$subject = $split_line[0].' '.$split_line[1].' '.trim($data_array[3]);



# Send the e-mail.

        $recipient = $emailrecip;
        $body_of_email = trim($data);

        $header = 'From: "' . $emailfromname . '" <' . $emailfromaddr . '>';
        $header .= "\n"; 
        $header .= "X-Priority: 1";
        $header .= "\n";

	        mail ($recipient, $subject, $body_of_email, $header);

        echo ("E-mail sent.");

?>

 

I kinda went a different direction with it.  The first 3 arrays work but the 4th one never seems to fire and I was wondering if anyone can tell me why.

 

Link to comment
https://forums.phpfreaks.com/topic/255096-small-help/#findComment-1309708
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.