我要替换破折号(&A);在此图像文件名中用空格下划线:
text1_text2-10212-etc_125.jpg (插件结果)
我的代码是:$string = preg_replace(\'/[\\-_]/\',\' \', $file[\'name\']);
我在试着str_replace
&;preg_replace
但它不起作用。此代码是Advanced Image Grabber插件(中)的一部分class_image_grabber.php
)
//takes an image url as argument and save is to media library
// return Null on failure
static public function imageUpload($imageUrl) {
$file = array();
$file[\'name\'] = basename($imageUrl);
$file[\'tmp_name\'] = download_url($imageUrl);
if (is_wp_error($file[\'tmp_name\'])):
@unlink($file[\'tmp_name\']);
return NULL;
endif;
$attachmentId = media_handle_sideload($file, 0);
// create the thumbnails
$attach_data = wp_generate_attachment_metadata( $attachmentId, get_attached_file($attachmentId));
wp_update_attachment_metadata( $attachmentId, $attach_data );
return $attachmentId;
}//EOF