Full Height iframe - php

In wordpress I'm using a plugin that create this iframe:
<iframe scrolling="no" allowfullscreen="" src="http://...k.jpg&is_stereo=false" width="100%" height="1200px"></iframe>
This is the array of the php page:
$a = shortcode_atts( array(
'img' => '',
'video' => '',
'pimg' => '',
'stereo' => 'false',
'width' => '100%',
'height' => '1200px',
), $atts );
and this the php code:
<iframe width="<?php echo $a['width']; ?>" height="<?php echo $a['height']; ?>" scrolling="no" allowfullscreen src="<?php echo $iframe_url; ?>"></iframe>
The width is perfect and responsive.
I need to have a full height iframe. How?

You can try and see if this works:
<div style="height: 100%; width: 100%;">
<iframe width="<?php echo $a['width']; ?>" height="<?php echo $a['height']; ?>" scrolling="no" style="height:100%;width:100%" allowfullscreen="1" src="<?php echo $iframe_url; ?>"></iframe>
</div>
OUTPUT SHOULD BE
<div style="height: 100%; width: 100%;">
<iframe scrolling="no" allowfullscreen="1" src="http://...k.jpg&is_stereo=false" style="height:100%;width:100%" width="100%" height="1200px"></iframe></div>

Related

PHP conditional echo text instead HTML

I'm trying to create a conditional for a theme in a Wordpress,
If the meta exist show this... else show that.
<?php
$scene_trailer = get_post_meta($post->ID, 'scene_trailer', true);
if ( $scene_trailer ) {
echo htmlentities('<div style="width: 645px; height: 364px; overflow: hidden">
<iframe src="http://tvguide.com/<?php $key="scene_number"; echo get_post_meta($post->ID, $key, true); ?>/" width="645" height="430" scrolling="no" frameborder="0" style="position: relative; top: -36px"></iframe></div>');
}
else {
echo '<img src="http://i0.tvguide.com/<?php $key="scene_number"; echo get_post_meta($post->ID, $key, true); ?>/576x324.jpg" width="576" height="324" alt="" />';
}
?>
My code returns this as plain text:
<div style="width: 645px; height: 364px; overflow: hidden"> <iframe src="http://tvguide.com<?php $key="scene_number"; echo get_post_meta($post->ID, $key, true); ?>/" width="645" height="430" scrolling="no" frameborder="0" style="position: relative; top: -36px"></iframe></div>
Can someone please show me what I'm doing wrong?
Thanks!
You have write wrong php syntax Please try below code.
<?php
$scene_trailer = get_post_meta($post->ID, 'scene_trailer', true);
if ($scene_trailer) {
$key = "scene_number";
$scene_number = get_post_meta($post->ID, $key, true);
echo htmlentities('<div style="width: 645px; height: 364px; overflow: hidden">
<iframe src="http://tvguide.com/' . $scene_number . '" width="645" height="430" scrolling="no" frameborder="0" style="position: relative; top: -36px"></iframe></div>');
} else {
echo '<img src="http://i0.tvguide.com/scenes/' . $scene_number . '/576x324.jpg" width="576" height="324" alt="" />';
}
?>

PHP find and replace html attribute in string

I get iframe from some api and i hold this iframe in some var.
I want to search for "height" and change his value to something else. the same with "scrolling".
For example:
<iframe src="someurl.com" width="540" height="450" scrolling="yes" style="border: none;"></iframe>
After the php function the iframe will be:
we have change the "height" to 600px and "scrolling" to no
<iframe src="someurl.com" width="540" height="600" scrolling="no" style="border: none;"></iframe>
i have solution with this code:
$iframe = preg_replace('/(<*[^>]*height=)"[^>]+"([^>]*>)/', '\1"600"\2', $iframe);
the problem is that after the "preg_replace" run it remove all html attributes after the "height"
Thanks
You can use DOMDocument for it. Something like this:
function changeIframe($html) {
$dom = new DOMDocument;
$dom->loadHTML($html);
$iframes = $dom->getElementsByTagName('iframe');
if (isset($iframes[0])) {
$iframes[0]->setAttribute('height', '600');
$iframes[0]->setAttribute('scrolling', 'no');
return $dom->saveHTML($iframes[0]);
} else {
return false;
}
}
$html = '<iframe src="someurl.com" width="540" height="450" scrolling="yes" style="border: none;"></iframe>';
echo changeIframe($html);
With this method you can modify iframe as you want.
Thanks.
An example as you requested:
$str = '<iframe src="someurl.com" width="540" height="450" scrolling="yes" style="border: none;"></iframe>';
$str = preg_replace('/height=[\"\'][0-9]+[\"\']/i', 'height="600"', $str);
$str = preg_replace('/scrolling=[\"\']yes[\"\']/i', 'scrolling="no"', $str);
echo $str; // -> '<iframe src="someurl.com" width="540" height="600" scrolling="no" style="border: none;"></iframe>'

Hide c_box when no input

i want if there is no input such as http://bloxhotel.nl/video?watch=YxIiPLVR6NA
That a box will not pop up
<?php
ob_start();
include 'includes/inc.bootstrap.php';
$page = Array('title' => ((isset($user)) ? $user->username : ''), 'onload' => ((isset($_GET['utm_source']) && $_GET['utm_source'] == 'welcome') ? 'Pixel.View.OpenUrlOverlay(\'/pixlett/Video.php\');' : ''), 'tab' => Array('me', 'home'), 'access' => Array(true, false));
include 'content/header.php';
include 'content/menu.php';
?>
<center>
<div class="c_box" style="overflow: hidden; width: 58%; height: 10%;">
<div class="heading blue">Ga naar Video</div>
<tr style="padding: 4px;">
<html>
<body>
<form action="welcome_get.php" method="get">
Youtube Link: <input type="text" name="link"><br>
<input type="submit">
</form>
</body>
</html>
</div>
<center>
<div class="c_box" style="overflow: hidden; width: 58%; height: 10%;">
<div class="heading blue">Video</div>
<?php
$watch = $_GET['watch'];
$embed = '<embed src="http://bloxhotel.nl/Player7.swf" flashVars="video_id='.$watch.'" style="width: 100%; height: 57%;" allowScriptAccess="always" autoplay="false" allowFullscreen="true" type="application/x-shockwave-flash" wmode="transparent" id="player_demo"></embed></object>';
echo $embed;
?>
</div>
</center>
This
<?php
$watch = $_GET['watch'];
$embed = '<embed src="http://bloxhotel.nl/Player7.swf" flashVars="video_id='.$watch.'" style="width: 100%; height: 57%;" allowScriptAccess="always" autoplay="false" allowFullscreen="true" type="application/x-shockwave-flash" wmode="transparent" id="player_demo"></embed></object>';
echo $embed;
?>
Need to not show up
So if there is no input in video?watch= the box needs to keep hidden
Can someone help
Do you expect something like this?
<?php
$watch = trim($_GET['watch']);
if($watch!=""){
?>
<div class="c_box" style="overflow: hidden; width: 58%; height: 10%;">
<div class="heading blue">Video</div>
<?php
$embed = '<embed src="http://bloxhotel.nl/Player7.swf" flashVars="video_id='.$watch.'" style="width: 100%; height: 57%;" allowScriptAccess="always" autoplay="false" allowFullscreen="true" type="application/x-shockwave-flash" wmode="transparent" id="player_demo"></embed></object>';
echo $embed;
?>
</div>
<?php } ?>
simply check
if(!empty($_GET['watch']) {echo $some_other_text; //or echo '';} else {echo $embed}
In that way, it will check weather the watch is empty or not.
you can also check if the ?watch is added or not as follow:
if(!isset($_GET['watch'])||!empty($_GET['watch'])) {//do not echo your box}
else {//echo your box}

Converting Html to PHP

Can anyone help me converting Html to PHP
I want to add a paypal button to my woocommerce website but I am running into a few errors.
here is the code I have in html format
<a class="paypal_checkout_button" href="websitelinkhere"><img src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" width="145" height="42" style="width: 145px; height: 42px; padding-top: 30px; padding-left:20px; " border="0" align="top" alt="Check out with PayPal"></a>
Basically im using the theme - theretailer.getbowtied.com/demo the shopping cart dropdown at the top of the main page im trying to add the button into that but cant get it to display
Any help would be amazing
Edit*
this is the page im trying to add the code to
<div class="gbtr_minicart_wrapper">
<div class="gbtr_minicart">
<?php echo '<a class="paypal_checkout_button" href="websitelinkhere"><img src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" width="145" height="42" style="width: 145px; height: 42px; padding-top: 30px; padding-left:20px; " border="0" align="top" alt="Check out with PayPal"></a>';?>
<?php
echo '<ul class="cart_list">';
if (sizeof($woocommerce->cart->cart_contents)>0) : foreach ($woocommerce->cart->cart_contents as $cart_item_key => $cart_item) :
$_product = $cart_item['data'];
if ($_product->exists() && $cart_item['quantity']>0) :
echo '<li class="cart_list_product">';
echo '<a class="cart_list_product_img" href="'.get_permalink($cart_item['product_id']).'">' . $_product->get_image().'</a>';
echo '<div class="cart_list_product_title">';
$gbtr_product_title = $_product->get_title();
//$gbtr_short_product_title = (strlen($gbtr_product_title) > 28) ? substr($gbtr_product_title, 0, 25) . '...' : $gbtr_product_title;
echo '' . apply_filters('woocommerce_cart_widget_product_title', $gbtr_product_title, $_product) . '';
echo '<div class="cart_list_product_quantity">'.__('Quantity:', 'theretailer').' '.$cart_item['quantity'].'</div>';
echo '</div>';
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf('×', esc_url( $woocommerce->cart->get_remove_url( $cart_item_key ) ), __('Remove this item', 'woocommerce') ), $cart_item_key );
echo '<div class="cart_list_product_price">'.woocommerce_price($_product->get_price()).'</div>';
echo '<div class="clr"></div>';
echo '</li>';
endif;
endforeach;
?>
<div class="minicart_total_checkout">
<?php _e('Cart subtotal', 'theretailer'); ?><span>
<?php echo $woocommerce->cart->get_cart_total(); ?></span>
</div>
<?php _e('View Shopping Bag', 'theretailer'); ?>
<?php _e('Proceed to Checkout', 'theretailer'); ?>
<?php
else: echo '<li class="empty">'.__('No products in the cart.','woocommerce').'</li>'; endif;
echo '</ul>';
?>
</div>
</div>
</div>
<span><?php echo $woocommerce->cart->cart_contents_count; ?></span>
</div>
Im looking for it to go under the buttons
Im looking for it to go into the gbtr_minicart section under the buttons
here you go
//some php code
?>
<a class="paypal_checkout_button" href="websitelinkhere"><img src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" width="145" height="42" style="width: 145px; height: 42px; padding-top: 30px; padding-left:20px; " border="0" align="top" alt="Check out with PayPal"></a>
<?php
//php code again
<?php
echo '<a class="paypal_checkout_button" href="websitelinkhere"><img src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" width="145" height="42" style="width: 145px; height: 42px; padding-top: 30px; padding-left:20px; " border="0" align="top" alt="Check out with PayPal"></a>';
?>

How to get images size fixed in php?

How do I get images in certain fixed size, example I've attached the image and codes for your review
Please click on this link (image) to understand my question
<img src="<?php echo $picfile; ?>" border="0" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>" align="left" style="border:1px solid black;margin-right:5px;">
You can get image details with
$details = get_image_size($filename).
$details[3] will contain the width and height in html format ready for you to use.
Could possibly try this
img src='$filename' style='width:250px; height: 250px'
allows you to strech image to specific size
to scale you could use
img src='$filename' style='width:auto; height: 250px'
There are a few ways to do this. As you are looping through your images, you want to keep track of the maximum width.
$newImageArray = array();
$maxWidth = 0;
$maxHeight = 0;
$i = 0;
forEach ( $imageArray as $picfile ) {
$newImageArray[$i]['picFile'] = $picfile;
$imgsize = get_image_size($picfile);
$newImageArray[$i]['width'] = $imgsize[0];
if ( $imgsize[0] > $maxWidth ) {
$maxWidth = $imgsize[0];
}
$newImageArray[$i]['height'] = $imgsize[1];
if ( $imgsize[1] > $maxHeight ) {
$maxHeight = $imgsize[1];
}
$1++;
}
forEach ( $newImageArray as $i) { ?>
<img src="<?php echo $picfile; ?>" border="0" width="<?php echo $maxWidth; ?>" height="<?php echo $maxHeight; ?>" align="left" style="border:1px solid black;margin-right:5px;">
<?php
}
Now you shouldn't really be doing this. A CSS based option would work better. You can add a wrapper container with a width on it and set the images to display:block;width:100%; and the images will always fill the space. I will edit with that solution shortly.
This will keep the image within a fixed width, and scale the image to fit inside of the box when it is too large.
HTML:
<div class="imgWrap">
<img src="http://www.captainangry.com/img/1236647133510anonib.jpg">
</div>
CSS:
.imgWrap {
width:100px;
height:100px;
float:left;
}
.imgWrap img {
display:block;
max-width:100%;
}
If you don't want to do any work in PHP then just wrap the image in a div and set overflow:hidden. This assumes that you know the height you want all of your images to be.
<div style="width:<?php echo $imgsize[0]; ?>; height:100px; overflow:hidden; border:1px solid black; margin-right:5px">
<img src="<?php echo $picfile; ?>" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>">
</div>

Categories