这是拖尾这是成功回答了我的其他问题:stackoverflow.com/questions/8597929/need-to-create-li-with-list-of-different-链接-使用-PHP-爆炸法需要补充的第二行和第三分隔符在PHP爆炸
所以我现在这样的:
text1:text1-page-url
text2:new-text2-page
text3:different-page-text3
:
<?php
$separator1 = "\n";
$separator2 = ":";
$textarea = get_custom_field('my_custom_output');
$array = explode($separator1,$textarea);
$output = ''; // initialize the variable
foreach ($array as $item) {
list($item_text, $item_links) = explode($separator2, trim($item));
$output .= '<li class="link-class"><a title="' . $item_text . '" href="http://mywebsite.com/' . $item_links . '">' . $item_text . '</a></li>';
}
?>
<ul>
<?php print $output; ?>
</ul>
并且,使用在其被定义为 “my_custom_output” 一个textarea以下和结果我s
text1
text2
text3
它们被成功链接和设计。 (我没有让他们的链接,因为stackoverflow不让我发布超过两个链接,因为我只有3代表)。
所以我的未来和希望的最终任务是要做到这一点:
text1
description 1
text2
description 2
text3
description 3
其中的text1等链接像以前一样,但这些描述没有联系。
所以我会尽我所能,就在这里的计算器,来试试吧。不过,我希望我会需要一些帮助。让我们去:
<?php
$separator1 = "\n";
$separator2 = ":";
$separator3 = ";";
$textarea = get_custom_field('my_custom_output');
$array = explode($separator1,$textarea);
$output = ''; // initialize the variable
foreach ($array as $item) {
list($item_text, $item_links) = explode($separator2, trim($item));
$output .= '<li class="link-class"><a title="' . $item_text . '" href="http://mywebsite.com/' . $item_links . '">' . $item_text . '</a><br /><span class="desc-class">' . $item_desc . '</span></li>';
}
?>
<ul>
<?php print $output; ?>
</ul>
,并使用下列其中是定义textarea的以 “my_custom_output”:
text1:text1-page-url;Text1 Description
text2:new-text2-page;Description For Text2
text3:different-page-text3;A Text3 Description
,我需要的输出是:
我不知道是否会分号的工作,但我不能使用空格(\ S),因为有空间在描述中。我乐于接受建议。
============================================== ======
我的最新尝试:
<?php
$separator1 = "\n";
$separator2 = ":";
$separator3 = ";";
$textarea = get_custom_field('my_custom_output');
$array = explode($separator1,$textarea);
$output = ''; // initialize the variable
foreach ($array as $item) {
$itemarray = explode($separator2, trim($item));
$item_text = $itemarray[0];
list($item_links, $item_desc) = explode($separator3,$itemarray[1]);
$output .= '<li class="link-class"><a title="' . $item_text . '" href="http://mywebsite.com/' . $item_links . '">' . $item_text . '</a><br /><span class="desc-class">' . $item_desc . '</span></li>';
}
?>
<ul>
<?php print $output; ?>
</ul>
IT WORKS! = d
会使用逗号工作(遵循典型的CSV)? – mc10 2011-12-22 01:17:38
我这么认为。感谢您的建议!分号看起来像它也可以工作。 =)可能很好,如果我想添加第四个分隔符8) – 2011-12-22 01:34:51