如果字符串由逗号分隔,
你可以explode 此时将字符串分为多个部分(项目数组)。如果字符串由其他内容分隔,例如空格或|
然后引爆它。
<?php
//assuming your string might look like: "USA, Canada, Japan, Russia"
$countries = bp_member_profile_data( \'field=Countries\' );
$array = explode(",", $countries);
//$array[0] = USA
//$array[1] = Canada
//$array[2] = Japan
//$array[3] = Russia
if ( ! empty( $countries ) ) {
echo \'<ul>\';
foreach ( $array as $country ) {
printf( \'<li>%s</li>\', $country );
}
echo \'</ul>\';
}
/* Result
<ul>
<li>USA</li>
<li>Canada</li>
<li>Japan</li>
<li>Russia</li>
</ul>
*/
?>