PHP variables how to line up in the foreground HTML textarea and how to change the line changes in the PHP background to get

Source: Internet
Author: User
This article mainly introduces the PHP variable in the foreground HTML textarea how to wrap and change the line changes in the PHP background, has a certain reference value, now share to everyone, the need for friends can refer to

The problem seems simple and easy. Looks like a change line <br/> Not to be able to, but, really did not imagine in so simple ah ah ah ah Ah!!!

First, line-break

Old practice: Based on thinkphp, the array is taken out from Redis, displayed in the foreground, but wrapped.

Background:

[PHP] view plain copy

function Tags_keywords () {           $this->showheadertitle (' tags_keywords ');         $redis = D ("Redis");         $keywords _list = $redis->smembers ("Budou:segmentation:sourse"); Gets the data and wraps the display in the foreground textarea.         $this->assign (' keywords_list ', $keywords _list);         $this->display ();    }

Front desk:

[HTML] view plain copy

<textarea name= "Keywords_area" style= "Overflow:auto; Display:inline; width:884px; height:298px; "rows=" 4 "cols=" >  <volist name= ' keywords_list ' id= ' key ' >  {$key}\r\n      //useless  </volist>  </textarea>

Finally found whether add \ r \ n or <br/> will not work. I'm out of my mind. Completely.

Originally, this \ r \ n should be added to the PHP code. The front desk only needs to read it. Wipe.

Again:

[PHP] view plain copy

function Tags_keywords () {                   $this->showheadertitle (' tags_keywords ');                 $redis = D ("Redis");                 $keywords _list = $redis->smembers ("Budou:segmentation:sourse");                 $textarea = "";                 foreach ($keywords _list as $value) {                         $textarea. = $value. " \ n ";                 }                 $this->assign (' keywords_list ', $textarea);                 $this->display ();            }

[HTML] view plain copy

<textarea name= "Keywords_area" style= "Overflow:auto; Display:inline; width:884px; height:298px, "rows=" 4 "cols=" >{$keywords _list}</textarea>

That's just right. There is also a little <textarea> content </textarea>. The contents of the content are written in one line, otherwise, there will be spaces in the page display.

Second, PHP gets the content of Texteara in the line

In the foreground Texteara after the line, commit, PHP through $_post[' Texterea '] to get the string, is to be processed, or get a whole string.

[PHP] view plain copy

function Modify_keywords_list () {                   $keywords _post = $_post[' Keywords_area '];                 $keywords _post = nl2br ($_post[' Keywords_area ');  Replace line with <BR/>                 $keywords _post = explode ("<br/>", $keywords _post);//Then use <br/> as the delimiter to become an array. Although it becomes an array, or value or there is a space, to go to the space                 foreach ($keywords _post as $key) {                            if (trim ($key)) {  //remove whitespace.                                 $redis->sadd ("Budou:segmentation:sourse", Trim ($key));//go to space.                          }                   }                          }
      1. First Use the PHP function: nl2br () to convert the line break to <br/>

2. Use the PHP function: Explode (' <br/> ', $data) to split the array.

3. Then use the PHP function: Trim (), and remove the space for each value.

Get....

Related recommendations:

Memory Management for PHP variables

PHP variable reference vs. non-reference performance comparison

Related Article

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.