php - 将 Pregmatch 值存储在变量中
问题描述
我有下面的代码从 $string 中单独删除 URL。我希望 Match[0] 的这个值在动态生成的 Iframe URL 中得到回显。我得到 1 作为输出..
<?php
$string = '<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3887.094472437723!2d77.7214372148226!3d13.029655590817852!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3bae1037f4ecfb4b%3A0xe7e06043fc59c9f2!2sConcorde%20Auriga!5e0!3m2!1sen!2sin!4v1575539767295!5m2!1sen!2sin" width="600" height="450" frameborder="0" style="border:0;" allowfullscreen=""></iframe>';
preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $string, $match);
echo "<pre>";
print_r($match[0]);
echo "</pre>";
?>
我尝试了什么:
<div id="locate-us"></div>
<div class="decoration decoration-margins"></div>
'; // end content
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $_POST['property_maps_url'], $match);
print_r($match[0]);
// continue in content
$content_to_write_amp .=' <amp-iframe class="full-bottom" width="600" height="400" layout="responsive" sandbox="allow-scripts allow-same-origin allow-popups" frameborder="0" src="'.print_r($match[0]).'"></amp-iframe>
</div>
解决方案
你剥离的 url 是 $match[0] 的第 0 个元素,所以像这样打印它 $match[0][0]。
以下是您的 div 的代码。
<div class="decoration decoration-margins"></div>
'; // end content
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $_POST['property_maps_url'], $match);
print_r($match[0]);
// continue in content
$content_to_write_amp .=' <amp-iframe class="full-bottom" width="600" height="400" layout="responsive" sandbox="allow-scripts allow-same-origin allow-popups" frameborder="0" src="'.$match[0][0]).'"></amp-iframe>
</div>
推荐阅读
- android - 警告:忽略匿名内部类的 InnerClasses 属性
- google-cloud-platform - 使用 FDW 扩展从本地数据库到 Cloud SQL 是否可能或可行?
- android - 如何将训练有素的 scikit-learn 模型导入 android 项目
- arrays - Pandas 字节数组到十六进制转换
- javascript - javascript捕获img src“...”之间的所有内容
- java - JAVA KeyEvent 序列化错误
- macos - 具有有效签名的 macOS Kext 在第二次安装后被拒绝(高山脉)
- python - 我怎样才能摆脱循环?
- php - 遍历 wp_get_post_terms 并回显分类名称
- common-lisp - Common lisp values-list 函数