PHP 在某些子字符串处遍历字符串和换行符



如果我有这个长字符串:

WAITLIST, 91630, ACCY 2001 , 10, Intro Financial Accounting, 3.00, Zou, Y, DUQUES 251,     TR09:35AM   - 10:50AM, 01/13/14   - 04/28/14 , , WAITLIST, 90003, ACCY 2001 , 11, Intro Financial Accounting, 3.00, Zou, Y, DUQUES 254, TR11:10AM - 12:25PM, 01/13/14 - 04/28/14 , , OPEN, 91212, ACCY 2001 , 12, Intro Financial Accounting, 3.00, Zou, Y, 1957 E B12, TR02:20PM - 03:35PM, 01/13/14 - 04/28/14 , , WAITLIST, 90004, ACCY 2002 , 10, Intro Managerial Accounting, 3.00, Linsley, C, FNGR 222, TR11:10AM - 12:25PM, 01/13/14 - 04/28/14 , , 

我想搜索","并在每次出现后直接添加换行符,所以我的长字符串看起来像这样:

WAITLIST 91630 ACCY 2001 10 Intro Financial Accounting 3.00 Zou, Y DUQUES 251 TR09:35AM - 10:50AM 01/13/14 - 04/28/14
WAITLIST 90003 ACCY 2001 11 Intro Financial Accounting 3.00 Zou, Y DUQUES 254 TR11:10AM - 12:25PM 01/13/14 - 04/28/14 
OPEN 91212 ACCY 2001 12 Intro Financial Accounting 3.00 Zou, Y 1957 E B12 TR02:20PM - 03:35PM 01/13/14 - 04/28/14 
ETC....

我想我可以使用条带来记录每个", "的位置并将其添加到数组中。然后我可以使用 for 循环遍历数组,并在每个双逗号的位置后附加一个"
"。这样行得通吗?干杯!

只需使用 str_replace 将字符串替换为 <br>

$result = str_replace(", ,", "<br>", $str);

尝试str_replace

$str = 'WAITLIST, 91630, ACCY 2001 , 10, Intro Financial Accounting, 3.00, Zou, Y, DUQUES 251,     TR09:35AM   - 10:50AM, 01/13/14   - 04/28/14 , , WAITLIST, 90003, ACCY 2001 , 11, Intro Financial Accounting, 3.00, Zou, Y, DUQUES 254, TR11:10AM - 12:25PM, 01/13/14 - 04/28/14 , , OPEN, 91212, ACCY 2001 , 12, Intro Financial Accounting, 3.00, Zou, Y, 1957 E B12, TR02:20PM - 03:35PM, 01/13/14 - 04/28/14 , , WAITLIST, 90004, ACCY 2002 , 10, Intro Managerial Accounting, 3.00, Linsley, C, FNGR 222, TR11:10AM - 12:25PM, 01/13/14 - 04/28/14 , ,';
$val = str_replace(', ,', '<br />', $str);
echo $val;

相关内容

  • 没有找到相关文章

最新更新