Jump to content

Line breaks and arrays


dca_steve

Recommended Posts

Hi all - I have a form where I'm gathering info from a drop-down list, and placing what the user selects into an array (the user can select more than one item from the drop-down).  I then want to take the selections from the array, and put them into an email with line breaks between each item the user selected.  This is working except the first 2 entries are always run together, with no line break.  Here's a portion of what my generated email looks like:

 

******

If yes, please identify the Accrediting Agency:

Accreditation Commission for Acupuncture and Oriental Medicine Accrediting Bureau of Health Education Schools

American Podiatric Medical Association Council on Podiatric Medical Education 

******

 

This should look like this instead:

 

*****

If yes, please identify the Accrediting Agency:

Accreditation Commission for Acupuncture and Oriental Medicine

Accrediting Bureau of Health Education Schools

American Podiatric Medical Association Council on Podiatric Medical Education 

*****

 

Not sure why the first 2 items are run together.  Here is how I define the array:

$accred_agency_form = implode("\r\n", $_POST['accred_agency']);

 

And how it looks as far as being put into the body of the email:

$body .= "If yes, please identify the Accrediting Agency:\n".$accred_agency_form."  \n\n";

 

Any ideas?  Thanks! :confused:

Link to comment
Share on other sites

Why are you using Windows line-breaks (\r\n) in your implode, but Unix line-breaks (\n) for the rest?

 

Have you checked the raw output of $accred_agency_form? Perhaps the \r\n is there, but client-side behaviour is causing it to display improperly.

 

I've never seen implode fail to insert a delimiter between array values.

 

Perhaps you should also verify $_POST['accred_agency'] is structured the way you expect.

Link to comment
Share on other sites

xyph - thanks for the quick reply.  As far as using windows/UNIX breaks, I've been trying everything to solve this and that's what I've been using now.  Earlier tried just \n and that wasn't working.

 

Just did an echo $accred_agency_form; on the array and got this:

Accreditation Commission for Acupuncture and Oriental Medicine Accrediting Bureau of Health Education Schools American Board of Funeral Service Education Committee on Accreditation

 

Assume I should be seeing this instead....

Accreditation Commission for Acupuncture and Oriental Medicine

Accrediting Bureau of Health Education Schools

American Board of Funeral Service Education Committee on Accreditation

 

Not sure what to do from here?

Link to comment
Share on other sites

Just realized that it doesn't matter how many items I select from the drop down, it does put in a line break, but just one.  So for instance if I select 3 items, it runs the first 2 together, then puts in a line break and correctly places the 3rd item next.  If I select 6 items, it runs the first 5 together, puts in a break, then places the 6th item correctly, etc.

 

It seems to think the only place a line break should be is immediately before the very last item selected. 

 

Not sure how to correct this....

Link to comment
Share on other sites

You're viewing the output in HTML, not plain text. View the source of the page, or output it surrounded by <pre> tags.

 

echo "<pre>Raw output:
*********
$accred_agency_form
*********
Raw array dump:";
print_r($_POST['accred_agency']);
echo "</pre>";

Link to comment
Share on other sites

xyph - you rock, thanks.  So I did what you said and got this....looks good huh? 

 

Raw output:

*********

Accreditation Commission for Acupuncture and Oriental Medicine

Accreditation Commission for Midwifery Education

Accrediting Bureau of Health Education Schools

Accrediting Commission of Career Schools and Colleges

*********

Raw array dump:Array

(

    [0] => Accreditation Commission for Acupuncture and Oriental Medicine

    [1] => Accreditation Commission for Midwifery Education

    [2] => Accrediting Bureau of Health Education Schools

    [3] => Accrediting Commission of Career Schools and Colleges

)

 

So since it still looks incorrect in my email, the culprit may 'client-side behavior' you are talking about?

Link to comment
Share on other sites

Apparently. It seems to be displaying wonderfully in your browser.

 

Have you tried checking the email with another client? Have you specifically declared the e-mail as text/plain in you email headers?

Link to comment
Share on other sites

Weird, it's sending the body in base64.

 

Your mail server might be wonking this up :/

 

Can we see the entire script? It's odd that some fields are registering line-breaks properly. It's also very odd only the last line-break registers in the decoded email, when your source data has line-breaks between each option.

Link to comment
Share on other sites

Here's the top part (btw gotta go to lunch will be back in an hour or so)...thanks for checking this out for me xyph, you've been a huge help!

 

<?php 
//session_start();
require('captcha/captcha.php');
include('mysql_connect.php');
$captcha_passed = 0;


$date_submitted = date('n/j/Y g:i:s A');
$report_year_form = addslashes($_POST['report_year']);
$institution_name_form = addslashes($_POST['institution_name']);
$institution_code_form = addslashes($_POST['institution_code']);
$street_address_form = addslashes($_POST['street_address']);
$city_form = addslashes($_POST['city']);
$state_form = addslashes($_POST['state']);
$zip_code_form = addslashes($_POST['zip_code']);
$branch_locations_form = addslashes($_POST['branch_locations']);
$satellite_locations_form = addslashes($_POST['satellite_locations']);
$current_asmnts_form = addslashes($_POST['current_asmnts']);
$disp_action_form = addslashes($_POST['disp_action']);
$inst_recognized_form = addslashes($_POST['inst_recognized']);
//$accred_agency_form = implode($_POST['accred_agency'],"\n");
$accred_agency_form = implode("\n", $_POST['accred_agency']);
$accred_agency_form_db = implode(",",$_POST['accred_agency']);
$accred_specialized_form = addslashes($_POST['accred_specialized']);
$higher_aid_form = addslashes($_POST['higher_aid']);
$veteran_ed_form = addslashes($_POST['veteran_ed']);
$cal_aid_form = addslashes($_POST['cal_aid']);
$add_fin_aid_form = addslashes($_POST['add_fin_aid']);
$fin_aid_program_form = addslashes($_POST['fin_aid_program']);
$doc_degrees_form = addslashes($_POST['doc_degrees']);
$enroll_doctorate_form = addslashes($_POST['enroll_doctorate']);
$mas_degrees_form = addslashes($_POST['mas_degrees']);
$enroll_master_form = addslashes($_POST['enroll_master']);
$bac_degrees_form = addslashes($_POST['bac_degrees']);
$enroll_bachelor_form = addslashes($_POST['enroll_bachelor']);
$asc_degrees_form = addslashes($_POST['asc_degrees']);
$enroll_associate_form = addslashes($_POST['enroll_associate']);
$dip_cert_form = addslashes($_POST['dip_cert']);
$enroll_cert_form = addslashes($_POST['enroll_cert']);
$inst_catalog_form = addslashes($_POST['inst_catalog']);
$link_catalog_form = addslashes($_POST['link_catalog']);
$user_email = $_REQUEST['user_email'];
$accred_agency_form_array = explode(",",$accred_agency_form_db);


if(isset($_POST['Submit2'])){
   if($_SESSION['captchacode'] == $_POST['captcha']){
  
     
//set query
$query= 'Insert into report_profile_dev Set
date_submitted = "'.$date_submitted.'",
ip_address = "'.$_SERVER['REMOTE_ADDR'].'", 
report_year = "'.$report_year_form.'",
institution_name = "'.$institution_name_form.'", 
institution_code = "'.$institution_code_form.'", 
street_address = "'.$street_address_form.'", 
city = "'.$city_form.'", 
state = "'.$state_form.'", 
zip_code = "'.$zip_code_form.'", 
branch_locations = "'.$branch_locations_form.'", 
satellite_locations = "'.$satellite_locations_form.'", 
current_asmnts = "'.$current_asmnts_form.'", 
disp_action = "'.$disp_action_form.'",
inst_recognized = "'.$inst_recognized_form.'",
accred_agency = "'.$accred_agency_form.'",
accred_specialized = "'.$accred_specialized_form.'",
higher_aid = "'.$higher_aid_form.'",
veteran_ed = "'.$veteran_ed_form.'",
cal_aid = "'.$cal_aid_form.'",
add_fin_aid = "'.$add_fin_aid_form.'",
fin_aid_program = "'.$fin_aid_program_form.'",
doc_degrees = "'.$doc_degrees_form.'", 
enroll_doctorate = "'.$enroll_doctorate_form.'", 
mas_degrees = "'.$mas_degrees_form.'", 
enroll_master = "'.$enroll_master_form.'", 
bac_degrees = "'.$bac_degrees_form.'", 
enroll_bachelor = "'.$enroll_bachelor_form.'", 
asc_degrees = "'.$asc_degrees_form.'", 
enroll_associate = "'.$enroll_associate_form.'", 
dip_cert = "'.$dip_cert_form.'", 
enroll_cert = "'.$enroll_cert_form.'", 
inst_catalog = "'.$inst_catalog_form.'", 
link_catalog = "'.$link_catalog_form.'"';

$result = mysql_query($query);

echo "<pre>Raw output:
*********
$accred_agency_form
*********
Raw array dump:";
print_r($_POST['accred_agency']);
echo "</pre>";

//echo $query;
$to = $_POST['user_email'];
$header = "From: Annual Report Institution Data <do_not_reply_to_this@dca.ca.gov>\r\n";
$header .= "Bcc: test.mail@dca.ca.gov\r\n";
$subject = "Annual Report Institution Data";
$body = "ANNUAL REPORT INSTITUTION DATA \n\n\n\n";
$body .= "Reporting Year:  ".$report_year_form."\n\n";
$body .= "Institution Name:  ".$institution_name_form."\n\n";
$body .= "Institution Code:  ".$institution_code_form."\n\n";
$body .= "Street Address:  ".$street_address_form."\n\n";
$body .= "City:  ".$city_form."\n\n";
$body .= "State:  ".$state_form."\n\n";
$body .= "ZIP Code:  ".$zip_code_form."\n\n";
$body .= "Number of Branch Locations:  ".$branch_locations_form."\n\n";
$body .= "Number of Satellite Locations:  ".$satellite_locations_form."\n\n";
$body .= "Is this institution current with all assessments to the Student Tuition Recovery Fund?:  ".$current_asmnts_form."   \n\n";
$body .= "Is your institution  approved by an accrediting agency recognized by the United States Department of Education? Please include only full institutional approval, not programmatic approval:  ".$inst_recognized_form."   \n\n";
$body .= "If yes, please identify the Accrediting Agency:\n  ".$accred_agency_form."   \n\n";
$body .= "If your institution has specialized accreditation from a recognized United States Department of Education approved specialized/programmatic accreditor, please list the accreditation:  ".$accred_specialized_form."   \n\n";
$body .= "Has any accreditation agency taken any formal disciplinary action against this institution?:  ".$disp_action_form."   \n\n";
$body .= "Does your institution participate in federal financial aid programs under Title IV of the Federal Higher Education Act?:  ".$higher_aid_form."   \n\n";
$body .= "Does your institution participate in federal veteran's financial aid education programs?:  ".$veteran_ed_form."   \n\n";
$body .= "Does your institution participate in California financial aid programs, such as the Cal Grant program?:  ".$cal_aid_form."   \n\n";
$body .= "Does your institution participate in, or offer any additional financial aid program?:  ".$add_fin_aid_form."   \n\n";
$body .= "Additional financial aid program:  ".$fin_aid_program_form."   \n\n";
$body .= "Number of Doctorate Degrees Offered:  ".$doc_degrees_form."   \n\n";
$body .= "Number of Students enrolled in Doctorate level programs at this Institution:  ".$enroll_doctorate_form."    \n\n";
$body .= "Number of Master Degrees Offered:  ".$mas_degrees_form."    \n\n";
$body .= "Number of Students enrolled in Master level programs at this institution:  ".$enroll_master_form."     \n\n";
$body .= "Number of Bachelor Degrees Offered:  ".$bac_degrees_form."    \n\n";
$body .= "Number of Students enrolled in Bachelor level programs at this institution:  ".$enroll_bachelor_form."    \n\n";
$body .= "Number of Associate Degrees Offered:  ".$asc_degrees_form."    \n\n";
$body .= "Number of Students enrolled in Associate level programs at this institution:  ".$enroll_associate_form."    \n\n";
$body .= "Number of Diploma or Certificate Programs Offered:  ".$dip_cert_form."    \n\n";
$body .= "Number of Students enrolled in Diploma or Certificate programs at this institution:  ".$enroll_cert_form."    \n\n";
$body .= "Link to your institutional catalog if it appears on your website:  ".$inst_catalog_form."    \n\n";
$body .= "Method by which you are providing your catalog:  ".$link_catalog_form."  \n\n";


mail($to, $subject, $body, $header);

$captcha_passed = 1;
session_destroy();
  }
}


?>

Link to comment
Share on other sites

This is very odd... Do the line-breaks show up properly in the database row?

 

Seems like base64 doesn't mess up linebreaks

<?php

header('content-type: text/plain');

$test = array('one','two','three');

$implode = implode("\n",$test);

echo $implode."\n\n";

$base64 = base64_encode($implode);

echo $base64."\n\n";

$back = base64_decode($base64);

echo $back;

?>

 

output

 

one
two
three

b25lCnR3bwp0aHJlZQ==

one
two
three

 

What happens if you implode using a double line-break? "\n\n"

Link to comment
Share on other sites

xyph - jackpot, sort of!  The double line break resulted in this in my email:

 

If yes, please identify the Accrediting Agency:

  Accreditation Commission for Acupuncture and Oriental Medicine

 

Accreditation Commission for Midwifery Education

 

Accrediting Bureau of Health Education Schools

 

Accrediting Commission of Career Schools and Colleges

 

Accrediting Council for Continuing Education and Training 

 

 

Soooo....that's better!  Thanks - gonna still mess around with it to get rid of that extra space...

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.