【发布时间】:2011-12-22 08:24:15
【问题描述】:
这是我的非链接的工作 php 分解代码:
<?php
$textarea = get_custom_field('my_custom_output');
$array = explode(',',$textarea);
$output = ''; // initialize the variable
foreach ($array as $item) {
$item = trim($item); // clear off white-space
$output .= '<li>' . $item . '</li>';
}
?>
<ul>
<?php print $output; ?>
</ul>
..以及定义“my_custom_output”的代码,我将其输入到我的 textarea 字段中:
text1,text2,text3,etc
..和成品:
- 文本1
- 文本2
- 文本3
- 等
这样就行了。 现在我想做的是让 text1 成为 mywebsite.com/text1-page-url/ 的链接
我能做到这一点:
<?php
$textarea = get_custom_field('my_custom_output');
$array = explode(',',$textarea);
$output = ''; // initialize the variable
foreach ($array as $item) {
$item = trim($item); // clear off white-space
$output .= '<li class="link-class"><a title="' . $item . '" href="http://mywebsite.com/' . $item_links . '">' . $item . '</a></li>';
}
?>
<ul>
<?php print $output; ?>
</ul>
现在,我希望 $item_links 只定义 URL 的其余部分。例如: 我想把这个输入到我的文本区域:
text1:text1-page-url,text2:new-text2-page,text3:different-page-text3
输出如下:
我想做的另一件事是将逗号更改为新行。我知道新行的代码是 \n 但我不知道如何将其换出。这样我就可以这样说:
text1:text1-page-url
text2:new-text2-page
text3:different-page-text3
我希望我让你明白这一点。我快到了,我只是卡住了。请帮忙。谢谢!
【问题讨论】: