Php 错误数组到字符串JPG错误
我想获取一个字符串来查找URL,将它们存储在一个数组中,并使用它们来构建自定义输出。问题是我得到一个错误,我有一个字符串到数组的转换 请注意第21行JPEG(数组)上的数组到字符串转换 有没有其他方法可以获取存储在数组中的URLPhp 错误数组到字符串JPG错误,php,regex,xml,url,search,Php,Regex,Xml,Url,Search,我想获取一个字符串来查找URL,将它们存储在一个数组中,并使用它们来构建自定义输出。问题是我得到一个错误,我有一个字符串到数组的转换 请注意第21行JPEG(数组)上的数组到字符串转换 有没有其他方法可以获取存储在数组中的URL function getURLSfromStringToImages($string) { $regex = '/https?\:\/\/[^" ]+/i'; preg_match_all($regex, $string, $matches);
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);
函数getURLSfromStringToImages($string){
$regex='/https?\:\/\/[^”]+/i';
preg_match_all($regex,$string,$matches);
//($matches[0]);
$tmp='';
$tmpArray=$matches;
如果(是_数组($tmpArray)){
$size=count($tmpArray);//使用count()函数确定数组大小
$index=0;
而($index<$size){
$tmp.=''。\n“
“.JPEG.”。\n”
“.”“\n”
“。”($tmpArray[$index])”。“\n”
“.”“\n”
“.”“\n\n”;
$index++;
}
}
echo$tmp;
}
$urls=getURLSfromStringToImages($a:3:{i:0;a:9:{s:22:“房地产”楼层“名称”;s:7:“卡滕”;s:23:“房地产”楼层“价格”;s:0:;s:31:“房地产”楼层“价格后缀”s:0:;s:22:“房地产”楼层“尺寸”;s:0:;s:30:“房地产”楼层“尺寸后缀”s:0:;s:26:“房地产”楼层“卧室:0:29:“房地产”房地产楼层描述;s:0:;s:23:“房地产楼层图像”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:“房地产”楼层“名称”s:6:“斯特勒”s:23:“房地产”楼层“价格”s:0:;s:31:“房地产”楼层“价格”后缀s:0:;s:22:“房地产”楼层“尺寸”“s:0:”s:30:”房地产楼层大小后缀“s:0:”s:26:”房地产楼层卧室“s:0:”s:27:”房地产楼层卫生间“s:0:”s:29:”房地产楼层描述“s:0:”s:23:”房地产楼层图像“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:“不动产地板价格”s:0:“不动产地板价格”s:31:“不动产地板价格后缀”s:0:“不动产地板价格后缀”s:0:“不动产地板尺寸”s:0:“不动产地板尺寸”s:30:“不动产地板尺寸”s:0:“不动产地板卧室”s:0:“不动产地板尺寸”s:26:“不动产卧室”s:0:“不动产浴室”s:27:“不动产地板尺寸”s:29:“不动产描述”s:不动产楼层图片“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";}}}');
打印(URL);
您需要两个循环
while ( $index < $size ) {
foreach($tmpArray[$index] as $path)
$tmp .= '<anhang location="REMOTE" gruppe="BILD">' . "\n"
. '<format>JPEG</format>' . "\n"
. '<daten>' . "\n"
. '<pfad>' . $path . '</pfad>' . "\n"
. '</daten>' . "\n"
. '</anhang>' . "\n \n";
$index ++;
}
while($index<$size){
foreach($tmpArray[$index]作为$path)
$tmp.='匹配项被获取到数组中。您只需要获取存储在$Matches[0]
中的完整匹配值
因此,使用
$tmpArray = $matches[0]; // not $tmpArray = $matches;
另外,只需使用$tmpArray[$index]
而不是“($tmpArray[$index])”
请参阅。使用$tmpArray=$matches[0];
,而不是$tmpArray=$matches;