這是拖尾這是成功回答了我的其他問題: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