English 中文(简体)
摘除最后 com[复制]
原标题:Get rid of last comma [duplicate]
  • 时间:2012-05-02 17:56:38
  •  标签:
  • php
  • string
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
Removing last comma in PHP?
Remove the last Comma from a string (PHP / Wordpress)

我有某些原因没有奏效的法典。 我试图做的是,从结果中去掉最后的ma子,但却赢得了 t。 这里是法典

 <?php do { 
  $activity_user_first_name = $row_product_activity[ user_first_name ];
  $activity_user_last_name = $row_product_activity[ user_last_name ];
  $name =  <a href=""> .$activity_user_first_name.   .$activity_user_last_name. </a>,  ;
  echo rtrim($name, ",");
 } while($row_product_activity = mysql_fetch_assoc($product_activity)) ?> like this

因此,我希望得到的结果就是这样。

Steve Jobs, Bill Gates, Sergey Brin, Larry Page like this

相反,我这样做了。

Steve Jobs, Bill Gates, Sergey Brin, Larry Page, like this

因此,我想删除Larry Page之后的 com号或任何其他最终名称。 我尝试了许多其他选择,但正如我所希望的那样,没有这样做。 任何建议都会受到赞赏。

最佳回答

我认为,一个更好的解决办法是,首先在没有拖车 com的情况下构筑铺。 将每个名字的链接划入一个阵列,然后只是重复一些微弱的结果。

<?php 
    $names=array();
    do { 
        $activity_user_first_name = $row_product_activity[ user_first_name ];
        $activity_user_last_name = $row_product_activity[ user_last_name ];
        $names[] =  <a href="#"> .$activity_user_first_name.   .$activity_user_last_name. </a> ;
    } while($row_product_activity = mysql_fetch_assoc($product_activity));

    echo implode( ,  , $names);    

?> Like This
问题回答

暂无回答




相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签