javascript - 可以使用 PHP 从外部 HTML 文件中获取 javascript 变量
问题描述
是否可以使用从外部文件PHP
中获取变量?Javascript
html
在这种情况下,我想得到var
src:
<script type="text/javascript">
var sources = [{
type: "video/mp4",
src: "https://cdn.example.mp4",
res: "Trailer",
label: "Trailer"
}];
etc.
</script>
解决方案
也许有更好的方法。
但这里有一个简单的方法:
<?php
$content = file_get_contents("path to javascript");
//Remove everything before the string
$src = substr($content, strpos($content, "src: \"")+6, 100);
//Remove everything after the string
$src = substr($src, 0, strpos($src, "\""));
?>
推荐阅读
- javascript - 后台脚本中的 chrome.webRequest 侦听器仅在打开扩展程序时触发?
- python - 如何为张量的每个切片运行迭代 2D 卷积?
- swift - SwiftUI 动画错误?
- python - 无法将 Tensorflow ssd_mobilenet_v1_fpn_coco 模型冻结到冻结 (.pb) 文件中
- c++ - 处理二进制文件 - 显示垃圾
- python - 如何在整数字符串上使用 eval() 函数?
- memory - Tez 执行引擎上的 Hive 作业在内存分配上失败
- flutter - Flutter Listview 颜色但文本在容器外仍然可见
- python - 此代码应该为每个场景生成随机的不同时间。但是,我得到了同样的时间。有没有更好的方法来做到这一点?
- bash - 是卷曲吗?它是一个帖子吗?从 bash 脚本“粘贴”到网站