我想获取一个字符串来查找URL,将它们存储在一个数组中并使用它们来构建一个客户输出。问题是我得到一个错误,我有一个字符串到数组转换。
注意第21行JPEG(数组)
上的数组到字符串转换
有些人可以帮助我,是否有其他方法可以获取存储在数组中的URL?
function getURLSfromStringToImages($string) {
$regex = '/https?\:\/\/[^" ]+/i';
preg_match_all($regex, $string, $matches);
//($matches[0]);
$tmp = '';
$tmpArray = $matches;
if ( is_array( $tmpArray ) ) {
$size = count( $tmpArray ); //array size by using count() function
$index = 0;
while ( $index < $size ) {
$tmp .= '<anhang location="REMOTE" gruppe="BILD">' . "\n"
. '<format>JPEG</format>' . "\n"
. '<daten>' . "\n"
. '<pfad>' . "($tmpArray[$index])" . '</pfad>' . "\n"
. '</daten>' . "\n"
. '</anhang>' . "\n \n";
$index ++;
}
}
echo $tmp;
}
$urls = getURLSfromStringToImages('a:3:{i:0;a:9:{s:22:"real_estate_floor_name";s:7:"Karnten";s:23:"real_estate_floor_price";s:0:"";s:31:"real_estate_floor_price_postfix";s:0:"";s:22:"real_estate_floor_size";s:0:"";s:30:"real_estate_floor_size_postfix";s:0:"";s:26:"real_estate_floor_bedrooms";s:0:"";s:27:"real_estate_floor_bathrooms";s:0:"";s:29:"real_estate_floor_description";s:0:"";s:23:"real_estate_floor_image";a:2:{s:2:"id";s:4:"4243";s:3:"url";s:70:"https://www.immo-verteiler.de/wp-content/uploads/2018/06/grundriss.jpg";}}i:1;a:9:{s:22:"real_estate_floor_name";s:6:"sterer";s:23:"real_estate_floor_price";s:0:"";s:31:"real_estate_floor_price_postfix";s:0:"";s:22:"real_estate_floor_size";s:0:"";s:30:"real_estate_floor_size_postfix";s:0:"";s:26:"real_estate_floor_bedrooms";s:0:"";s:27:"real_estate_floor_bathrooms";s:0:"";s:29:"real_estate_floor_description";s:0:"";s:23:"real_estate_floor_image";a:2:{s:2:"id";s:4:"4211";s:3:"url";s:76:"https://www.immo-verteiler.de/wp-content/uploads/2018/06/Hotel-Goestling.jpg";}}i:2;a:9:{s:22:"real_estate_floor_name";s:13:"lkjölkjölkj";s:23:"real_estate_floor_price";s:0:"";s:31:"real_estate_floor_price_postfix";s:0:"";s:22:"real_estate_floor_size";s:0:"";s:30:"real_estate_floor_size_postfix";s:0:"";s:26:"real_estate_floor_bedrooms";s:0:"";s:27:"real_estate_floor_bathrooms";s:0:"";s:29:"real_estate_floor_description";s:0:"";s:23:"real_estate_floor_image";a:2:{s:2:"id";s:4:"3907";s:3:"url";s:66:"https://www.immo-verteiler.de/wp-content/uploads/2018/05/klein.jpg";}}}');
print_r($urls);
答案 0 :(得分:0)
你需要两个循环
ms_uni = df['ms'].unique() #calculate the unique ms values
new_df_dict = { "ma":[], "SEM":[] } #later you will rename them
for un in range( len(ms_uni) ):
cms = ms_uni[un]
new_df_dict['ma'].append( cms )
new_df_dict['SEM'].append( df[ df['ms']==cms ]['SEM c/s'].mean() ) #advise: change the column name in a more safe SEM-c_s
new_df = pd.DataFrame(new_df_dict) #end of the dirty work
new_df.rename(index=str, columns={'ma':"mass amu", "SEM": "SEM c/s(mean over all cycles)"} )
另外,我建议您使用heredoc语法:https://www.php-space.info/php/space/heredoc-syntax.php
答案 1 :(得分:0)
匹配被获取到数组数组中。您只需获取存储在$tmpArray = $matches[0]; // not $tmpArray = $matches;
。
因此,请使用
$tmpArray[$index]
另外,只需使用"($tmpArray[$index])"
代替{{1}}。
请参阅PHP demo。