使用explode()函数将字符串转换成数组
语法:
array eplode(string separator,string string [,int limit ])
<form name="form1" method="post" action="test.php">
<table width="400" border="1" cellpadding="0" cellspacing="1" bordercolor="#FF9900" bgcolor="#CCFF66">
<tr align="center">
<td width="98" height="120">添加投票选项:</td>
<td width="223" height="120"><p>
<textarea name="content" cols="30" rows="5" dir="content"></textarea>
<br />
<span class="style1">注意:每个选项间用*分隔</span></p></td>
<td width="61" height="120"><input type="submit" name="submit" value="提交" /></td>
</tr>
</table>
</form>
<?php
if($_POST[submit]!=""){
$content=$_POST[content];
$data=explode("*",$content);
while(list($name,$value)=each($data)){
echo '<input type="checkbox" name="checkbox" value="chekbox">';
echo $value."\n";
}
}
?>
本文介绍如何利用PHP的explode()函数将用户输入的字符串转换为数组,并展示数组中的每个元素作为可选选项。通过设置表单接收用户输入的多个选项,使用explode()函数按'*'分隔符解析输入,然后遍历数组并在页面上显示每个选项。此过程展示了处理用户输入和数据展示的基本技巧。
140

被折叠的 条评论
为什么被折叠?



