Questions about PHP removing whitespace elements in arrays

Source: Internet
Author: User
PHP removes the problem of whitespace elements within an array
Shrimp Class Programmers:
I am just getting started PHP rookie. Now ask a question:
Because of the company needs, I downloaded and installed a roundcube wemail, according to the company's requirements to write some of the necessary plug-in procedures. When I write the forwarding address, I write the address to be forwarded in a variable, and then use the explode () function to enter the symbol separated into the elements of each array, but found that as long as the last element is always empty, how to also delete this element, this problem has plagued me for three days. Special to ask you, the following are the relevant procedures:
Fields obtained from the database
$user _saved_forward_email=forwardemail_qry (); Create a record set
$field _id= ' forward_email_addresss ';

if ($user _saved_forward_email!=null)
{
$myemail = ";
$email _arr= explode (";", $user _saved_forward_email[1]);//If forwarding is allowed, then ";" Separates the elements from the data table and displays them

foreach ($email _arr as $k = $v)
{
if ($k =count ($email _arr-1))
{
$myemail = $myeamil. $v;
}else{
$myemail = $myemail. $v. chr (10);
}
}

HTML Display foreground format:
$input _textarea = new Html_textarea (Array (' name ' = ' = ' forward_email_address ', ' id ' = ' = ' $field _id,
' Rows ' =>24, ' cols ' =>80, ' wrap ' =>true, ' value ' = $myemail));

Convert the string entered by the foreground into an array, and then use CHR (10) to separate each element from the set, and finally to ";" Delimited write-in database
$forward _email_address = get_input_value (' forward_email_address ', rcube_input_post);
Convert all forwarded addresses to an array
$forward _email_address_array = Explode (CHR), $forward _email_address);
Count the number of array elements $aaa;
$forward _address =array_unique ($forward _email_address_array); Get non-repeating array elements
if (count ($forward _address)!=count ($forward _email_address_array))//If there are duplicate messages
{
$forward _count =count ($forward _address);
$rcmail->output->command (' Display_message ', $this->gettext (' forward_repeat '), ' confirmation ');
return forwardemail_error;
}
$email _count =count ($forward _address);
$forward _email_address=null; Assign an initial value of NULL

for ($i =0; $i <= ($email _count-1); $i + +)//traversal of all array elements
{
if (strlen (Trim ($forward _address[$i)) >2)//If the element is not empty
{
if (Ereg ("^[_\.0-9a-z-]+@" ([0-9a-z][0-9a-z-]+\.) +[a-z]{2,3}$ ", Trim ($forward _address[$i]))//if e-mail format is met
{

if ($forward _address[$i]==$_session[' username ')//If forwarding is itself, an error message is returned
{
$rcmail->output->command (' Display_message ', $this->gettext (' forward_self '), ' confirmation ');
return forwardemail_error;

}else//Assign to $forward_email_address variable and add ";"
{
$forward _email_address =trim ($forward _email_address. $forward _address[$i]). ";";

}
}
else//If the element does not conform to the format it will return an error message!
{
$forward _email_enabled= "N";
$rcmail->output->command (' Display_message ', $this->gettext (' Forward_incorrect '), ' confirmation ');
echo "That e-mail Format is wrong!";
return forwardemail_error;
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.