0

大家好,我有一个 PHP 数组,它来自一个带有 2 组数据的 rss 提要。标题和描述。

(数组打印示例,我想编辑数组中的所有描述项,而不仅仅是一个索引)

[2] => ('Remembrance','Release Date: Thursday 19th April 2012')

我将如何操作描述字符串以在进入 mysql 表之前删除“发布日期:”?

这是我的其他代码:

$rss = simplexml_load_file('rss.xml');
$title = $rss->xpath('//title');  //finding the title tags in the xml document and loading into variable
$description = $rss->xpath('//description');

$rows=array();

foreach($result as $title){
  $rows[]="('".mysql_real_escape_string($title)."','".mysql_real_escape_string(array_shift($description))."')";
}
mysql_query("INSERT INTO Films (Film_Name, Film_Release) VALUES ".implode(',',$rows));
print_r($rows);
4

2 回答 2

2

你是str_ireplace不区分大小写的

例子

$rows = array ();
$array = array (); // So many array
$array [2] = array (
        'Remembrance',
        'Release Date: Thursday 19th April 2012' 
); // Sample array Value

foreach ( $array as $detail ) {
    $title = $detail [0];
    $desc = str_ireplace ( "Release Date:", "", $detail [1] );
    $desc = rim($desc);
    $rows [] = sprintf ( "('%s','%s')", mysql_real_escape_string ( $title ), mysql_real_escape_string ( $desc )   );
}

mysql_query("INSERT INTO Films (Film_Name, Film_Release) VALUES ".implode(',',$rows));
print_r($rows);
于 2012-04-16T10:59:09.263 回答
1

如果您只是想删除“发布日期:”字符串,请使用str_replace('Release Date: ', '', 'Release Date: Thursday 19th April 2012');

preg_replace()如果您的数据是动态的,请使用:preg_replace('#^[^\:] #', '', 'Release Date: Thursday 19th April 2012');

于 2012-04-16T11:00:41.763 回答