php - 如何在现有的 echo 中回显 iframe
问题描述
我想在已经存在的echo ($loop)中回显 iframe ($test2) ,但是这样做时我的网站没有加载。
问题出在哪里?
我认为这与echo
问题有关echo
。
<?php
function sac_getData($sac_lastID) {
global $wpdb, $table_prefix, $sac_lastID, $sacGetChat;
$loop = '';
if (isset($_GET['sac_nonce_receive']) && wp_verify_nonce($_GET['sac_nonce_receive'], 'sac_nonce_receive')) {
if ((isset($sacGetChat) && $sacGetChat === 'yes') && (!empty($sac_lastID) && is_numeric($sac_lastID))) {
$query = $wpdb->get_results("SELECT * FROM ". $table_prefix ."ajax_chat WHERE id > ". $sac_lastID ." ORDER BY id DESC", ARRAY_A);
for ($row = 0; $row < 1; $row++) {
if (isset($query[$row]) && !empty($query[$row]) && is_array($query[$row])) {
$id = isset($query[$row]['id']) ? $query[$row]['id'] : '';
$time = isset($query[$row]['time']) ? $query[$row]['time'] : '';
$name = isset($query[$row]['name']) ? $query[$row]['name'] : '';
$text = isset($query[$row]['text']) ? $query[$row]['text'] : '';
$url = isset($query[$row]['url']) ? $query[$row]['url'] : '';
$time = sac_time_since($time);
$user = get_user_by('slug', $name);
$X = get_user_meta( $user->ID, 'description', true);
$test2 = echo '<iframe width="100" height="40" src="https://X.com/'.$X.'" scrolling="no" frameborder="0"></iframe>';
$loop = $id .'---'. $test2 .'---'. $text .'---'. $time .' '. esc_html__('ago', 'X') .'---'. $url .'---';
}
}
}
}
echo $loop;
}
add_action('init', 'sac_getData');
?>
我试过这个。
<?php
function sac_getData($sac_lastID) {
global $wpdb, $table_prefix, $sac_lastID, $sacGetChat;
$loop = '';
if (isset($_GET['sac_nonce_receive']) && wp_verify_nonce($_GET['sac_nonce_receive'], 'sac_nonce_receive')) {
if ((isset($sacGetChat) && $sacGetChat === 'yes') && (!empty($sac_lastID) && is_numeric($sac_lastID))) {
$query = $wpdb->get_results("SELECT * FROM ". $table_prefix ."ajax_chat WHERE id > ". $sac_lastID ." ORDER BY id DESC", ARRAY_A);
for ($row = 0; $row < 1; $row++) {
if (isset($query[$row]) && !empty($query[$row]) && is_array($query[$row])) {
$id = isset($query[$row]['id']) ? $query[$row]['id'] : '';
$time = isset($query[$row]['time']) ? $query[$row]['time'] : '';
$name = isset($query[$row]['name']) ? $query[$row]['name'] : '';
$text = isset($query[$row]['text']) ? $query[$row]['text'] : '';
$url = isset($query[$row]['url']) ? $query[$row]['url'] : '';
$time = sac_time_since($time);
$user = get_user_by('slug', $name);
$test2 = get_user_meta( $user->ID, 'description', true);
$loop = $id .'---'. <?php echo '<iframe width="100" height="40" src="https://X.com/'.$test2.'" scrolling="no" frameborder="0"></iframe>':?> .'---'. $text .'---'. $time .' '. esc_html__('ago', 'simple-ajax-chat') .'---'. $url .'---';
}
}
}
}
echo $loop;
}
add_action('init', 'sac_getData');
?>
解决方案
你写:
$loop = $id .'---'. <?php echo '<iframe width="100" height="40" src="https://X.com/'.$test2.'" scrolling="no" frameborder="0"></iframe>':?> .'---'. $text .'---'. $time .' '. esc_html__('ago', 'simple-ajax-chat') .'---'. $url .'---';
此时您已经在 PHP 中了。使用另一个 PHP 标签是没有意义的。另外,不清楚你想用 ":?>" 完成什么;冒号有错。
消除这些问题并合并一些最终彼此相邻的字符串,结果如下:
$loop = $id .'---<iframe width="100" height="40" src="https://X.com/'.$test2.'" scrolling="no" frameborder="0"></iframe>---'. $text .'---'. $time .' '. esc_html__('ago', 'simple-ajax-chat') .'---'. $url .'---';
推荐阅读
- c++ - 从头文件中包含 SFML/Graphics.hpp 时“没有这样的文件或目录”
- mysql - 想要在最短的时间内使用 excel 表中的值更新 MySQL DB
- c# - Telerik RadGrid SelectionChanging 事件离开部分选定行
- laravel - Eloquent:在模型和迁移中定义关系之间的区别
- r - R: ggplot2 以英里为单位的比例尺
- sql-server - SQL Server - 在 SSMS 中关闭查询窗口后,全局范围的临时过程立即消失
- spring - emq 和 Spring AMQP
- reactjs - Reactjs 从同一目录导入
- reactjs - props 更改时刷新 React-Native FlatList - 使用 redux 管理状态
- python - OneHotEncoding 方法在 sklearn 中失败