Convert comma separated string into array

前端 未结 10 1563
南笙
南笙 2020-12-17 20:08

I have a comma separated string, which consists of a list of tags and want to convert it to array to get a link for every tag.

Example:

$string = \'h         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 20:46

    The workaround(!) would be to remove the unwanted trailing characters afterwards:

    $tagss = rtrim($tagss, ", ");
    

    This rtrim removes any mix of spaces and commas from the right end of the string.

    Btw, you could use str_getcsv instead of explode, which also handles input spaces better.

提交回复
热议问题