[英]Feed parsing, splitting string
Say I have the following: 说我有以下几点:
$cars = "auto1,auto2,auto3,auto4";
If I parse $cars
to insert the value in my database, I get a string like "auto1,auto2,auto3,auto4". 如果我解析
$cars
以在数据库中插入值,则会得到类似“ auto1,auto2,auto3,auto4”的字符串。
I want to split this string when I parse the feed into "auto1, auto2, auto3, auto4" - basically add spaces between words. 当我将提要解析为“ auto1,auto2,auto3,auto4”时,我想拆分此字符串-基本上在单词之间添加空格。 How can i do it?
我该怎么做?
Here's how I get values for $cars
: 这是我获取
$cars
值的方法:
$xml = simplexml_load_file($feed);
foreach( $xml->feedinfo as $feedinfo )
{
$cars = $feedinfo->cars;
[...]
}
Thank you 谢谢
If you just want to add spaces: 如果只想添加空格:
$cars = str_replace(',', ', ', $cars);
But you could also split it into an array of elements: 但是您也可以将其拆分为元素数组:
$cars = explode(',', $cars)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.