php - PHP中的非法字符串偏移警告
问题描述
我一直在尝试理解在实现我在网上获取的代码并对其进行修改以使 Wordpress [视频] 短代码响应之后遇到的一些错误,但我真的不知道在尝试后要更改什么来修复它一堆东西......这些是错误:
警告:第 41 行中的非法字符串偏移“高度”
警告:在...第 41 行遇到的非数字值
警告:在第 41 行...除以零
这是造成错误的代码的一部分:
$padding = ($meta['height']/$meta['width'])*100 - 25;
谁能帮助我理解和修复这些错误?这是完整的代码:
// OVERRIDE [VIDEO] SHORTCODE TO MAKE RESPONSIVE
// Thanks to: https://www.stirtingale.com/guides/2018/11/wordpress-video
function lookupIDfromURL($image_url) {
// basic lookup from DB to match media URL with media URL
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
return $attachment[0];
}
add_filter( 'wp_video_shortcode', function( $output ) {
// get SRC
// this is a bit hacky
preg_match( '@src="([^"]+)"@' , $output, $match );
$src = array_pop($match);
$src = preg_replace('/\?.*/', '', $src);
// get ID
$postid = lookupIDfromURL( $src );
$meta = wp_get_attachment_metadata($postid);
// let it autoplay
// and include playsinline to fix issues on iOS
$output = str_replace( "<video", "<video playsinline autoplay muted loop ", $output );
$output = str_replace( "controls=", "data-controls=", $output );
// wrap it all up
$str = preg_replace('/\<[\/]{0,1}div[^\>]*\>/i', '', $output);
$padding = ($meta['height']/$meta['width'])*100 - 25; // modified to include narrower height
$wrap = "<div class='embed-responsive' style='padding-bottom:". $padding ."%'>".$str."</div>";
$output = $wrap;
return $output;
} );
解决方案
推荐阅读
- sql - 其他表有外键时如何删除表中的行
- apache-kafka - 为什么kafka不创建主题?bootstrap-server 不是公认的选项
- apache-kafka - io.confluent.ksql.exception.KafkaTopicExistsException: when launching ksql-server-start ksql-server.properties
- azure - 在 foreach-object 循环中拆分字符串
- node.js - Openssl 命令在 AWS nodejs 中的文件名前自动添加“/openssl”,导致找不到文件错误
- python - Google ML Engine 上的批量预测
- javascript - hyperdb - 复制没有错误,但文档没有传播
- groovy - 有没有办法通过 Jenkins 脚本控制台使用 groovy 脚本清理 Jenkins Worflowjob 工作区?
- c# - 从Controller获取JSON数据到View中的Dropdown
- r - 我无法更改 facet_grid 中的标签名称