首页 > 解决方案 > 如何在现有的 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');
?>

标签: phpiframeecho

解决方案


你写:

$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 .'---';

推荐阅读