我有一个HTML表单,在地址要在文本框中输入然后PHP输出生成如下PHP代码的数据:
$address = $_POST["address"];
echo $address;
输出在单行中,如:
The Manager, Scotia bank Ltd,Cincinnati Finance Center,26 W。美国俄亥俄州辛辛那提市马丁·路德·金路45268
但是我需要以3-4行可读的方式输出。
。E表示每行","换行/换行-这样输出将是:
<经理>
丰业银行股份有限公司
辛辛那提金融中心,
26 W。马丁·路德·金路,
辛辛那提,
俄亥俄州45268 经理>
谁能帮我解一下?
如果输出显示在文本区:
$address = str_replace(",",",'n",$_POST['address']);
echo $address;
如果它在HTML:
$address = str_replace(",",",<br/>",$_POST['address']);
echo $address;
如果,
是您想要分割字符串的分隔符,则尝试在php中使用explode
$str = 'The Manager, Scotia bank Ltd,Cincinnati Finance Center,26 W. Martin Luther King Road, Cincinnati, Ohio 45268';
$arr = explode(',',$str);
print_r($arr);
查看手册了解更多
爆炸是您正在搜索的函数…
$str = 'The string';
$arr = explode(',',$str);
print_r($arr);
点击这里了解更多关于explosion的信息
可能是这样的:
implode(",'n", explode(",", $string));
可以使用explosion。试试这个:
<?php
$str= "The Manager, Scotia bank Ltd,Cincinnati Finance Center,26 W. Martin Luther King Road, Cincinnati, Ohio 45268";
$arr = explode(",",$str);
for($i=0;$i<count($arr);$i++)
{
if($i==(count($arr)-1))
$comma = "";
else
$comma = ",";
echo $arr[$i].$comma."<br>";
}