How to get url from link - php

I'm using Visual Composer in Wordpress. I have created own custom element.
Now I'm trying to figure out how to get url from link.
If I print {$a['link']} I get url and title:
url:http%3A%2F%2Fwww.url.com|title:url_title|
This should be pretty easy(?) but just could not figure it out.
return "<div class='icon_text_box'>
<a href='{$a['link']}'>
<div class='icon_image'><img src='$image_url' alt='icon' / ></div>
<div class='icon_text'>{$a['text_heading']}</div>
</a>
</div>";
Here is whole element

Related

Open slideshow image on new page

First time here and hoping someone can help me. Apologies if I've done anything wrong with regards to posting this question here...
I've created a slide show (using PHP) based on 8 images loaded from an SQL database (PHPMyAdmin)
I want to be able to click on any one image to open a new page which will then show a larger version of the same.
I've scoured the internet and various other forums but struggling to find any help.
Please let me know if you require any further information prior to providing an answer. Any help will be hugely appreciated.
<div class="mySlides">
<div class="numbertext"><?php echo $i . " / 8" ?></div>
<a href="http://stu10.lccwebtest.co.uk/getimage.php">
<img src="<?php echo $product["Product_Image"];?>" style="width:100%">
</div>
My suggestion would be to end the anchor tag after the image (so the image is part of the link), set it's target attribute to _blank (so it opens in a new page), and finally pass some reference to getimage.php (so it can load the larger image). For example:
<div class="mySlides">
<div class="numbertext"><?php echo $i . " / 8" ?></div>
<a href="http://stu10.lccwebtest.co.uk/getimage.php?id=<?php echo $product["ID"];?>" target="_blank">
<img src="<?php echo $product["Product_Image"];?>" style="width:100%">
</a>
</div>
I've made an assumption on what your primary key is for "products", replace "ID" in my example above with the correct primary key.
Based on further discussion we established that getimage.php has no other function other than to show the larger image. So in that case how about doing away with it and adding the larger image url directly to the anchor as in the below:
<div class="mySlides">
<div class="numbertext"><?php echo $i . " / 8" ?></div>
<?php $largerImageUrl = $product["Product_Image"]; //replace the code here with your actual larger image url for this slide ?>
<a href="<?php echo $largerImageUrl;?>" target="_blank">
<img src="<?php echo $product["Product_Image"];?>" style="width:100%">
</a>
</div>
That reduces a lot of extra work. The only times you'd need a script in the middle would be if the larger image location was a secret or you wanted to somehow record the number of times it was viewed or you wanted to display some other html around the image. In other words, if it had some other function.

PHP Simplehtmldom: Extra image url from data-src

I am trying to scrape a few images from a website by using the PHP Simplehtmldom library. Normally the image url is found in the 'src' but in this case the image url is found in the 'data-url'. I am having trouble to access the data-url value and I was hoping some could help me out.
Let's say I have the following code:
<section id="imagesContainer">
<div class="img">
<img data-src="https://example.com/image1.jpg" alt="imageAlt1">
</div>
<div class="img">
<img data-src="https://example.com/image2.jpg" alt="imageAlt2">
</div>
<div class="img">
<img data-src="https://example.com/image3.jpg" alt="imageAlt3">
</div>
</section>
I attempted to extract the image urls from the data-src with the following code but it doesn't return the image url:
foreach($html->find('#imagesContainer') as $imagesContainer) {
foreach($imagesContainer->find('img') as $image) {
echo $image->data-src;
}
}
How can I extract the image url from the data-src? Is it possible with the simplehtmldom or do I need a regex?
many thanks for your suggestion. This code, using XPath, works to extract the value of the data-url:
$image->getAttribute('data-src')

How to convert an html content to wordpress

I have the following html code that tried to place in my WordPress page.
html:
<div class="hovereffect">
<img src="<?php echo get_template_directory_uri() ?>phone.jpg" >
<div class="overlay">
<h2>Hover effect 9</h2>
<a class="info" href="#">link here</a>
</div>
</div>
At the moment everything is in the site except the image that does not show.
How can I use this code WordPress in a way that it can display the image?
I think you forget to tell which place it should get the images from. And you are also forgetting a semicolon after the get_template_directory_uri();.
This is an example, but here i'm telling which folder to get the image from:
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/your_image.jpg">
you can do that but it is not a good practice to paste this code as it is in WordPress editor,
upload this image in media and get link of that image
Edit page, select text mode from top right corner of your editor and paste code these i.e
<div class="hovereffect">
<img src="http://example.com/wp-content/uploads/2016/07/img.png" >
<div class="overlay">
<h2>Hover effect 9</h2>
<a class="info" href="#">link here</a>
</div>
</div>
Here is good practice create a template for that page and write there your code.
Image replace with feature image
Heading with page title.
Detail with page content
link with page permalink.
Not enough reputation to leave a comment so I will leave this as an answer instead.
Assuming phone.jpg is at the root of your theme, you're forgetting the / (slash) before phone.jpg.
It should be
<img src="<?php echo get_template_directory_uri(); ?>/phone.jpg" >
PHP won't get parsed inside a page. Just upload the image to the WordPress media library and link to it directly.

Tooltip not functioning when routed to a new url path

I have template php files for dates and sharing. 1 file is like this:
date-share.php:
<div class="date"><?php echo date('M d'); ?><span><?php echo date('Y'); ?></span></div>
<span class="plus"></span>Share
<!-- Tooltip -->
<div class="tooltip-social-network clearfix" style="margin-top: -10px">
<span class='st_facebook_large' displayText='Facebook'></span>
<span class='st_twitter_large' displayText='Tweet'></span>
<span class='st_googleplus_large' displayText='Google +'></span>
<span class='st_pinterest_large' displayText='Pinterest'></span>
<span class='st_instagram_large' displayText='Instagram Badge' st_username='mews'></span>
<span class='st_email_large' displayText='Email'></span>
</div>
I php include it to one of my views to avoid too much clutter, instead of putting it there.
<?php include('templates/date-share.php')?>
This is how it would look like in the view when the SHARE button is clicked.
The social media icons group is just a tooltip.
However, I rerouted the view to a new url path. So I added a PHP echo base_url to all the links to maintain the root path. But I'm not sure how to apply with the php include, so I didn't add any. It still appeared but the share button can't show the tooltip anymore.
Edit: added pic for clicked SHARE without the tooltip - rerouted to a different url path
You can use view method inside view to load other view/partials.
Make sure your date-share.php under following path `application/views/template/date-share.php'
Now inside your main view load your date-share.php as below.
$this->load->view('template/date-share.php');

Get specific html content from other site with PHP

I want to try and get the latest movie I checked on the IcheckMovies site and display it on my website. I don't know how, I've read about php_get_contents() and then getting an element but the specific element I want is rather deep in the DOM-structure. Its in a div in a div in a list in a ...
So, this is the link I want to get my content from: http://www.icheckmovies.com/profiles/robinwatchesmovies and I want to get the first title of the movie in the list.
Thanks so much in advance!
EDIT:
So using the file_get_contents() method
<?php
$html = file_get_contents('http://www.icheckmovies.com/profiles/robinwatchesmovies/');
echo $html;
?>
I got this html output. Now, I just need to get 'Smashed' so the content of the href link inside the h3 inside a div inside a div inside a list. This is where I don't know how to get it.
...
<div class="span-7">
<h2>Checks</h2>
<ol class="itemList">
<li class="listItem listItemSmall listItemMovie movie">
<div class="listImage listImageCover">
<a class="dvdCoverSmall" title="View detailed information on Smashed (2012)" href="/movies/smashed/"></a>
<div class="coverImage" style="background: url(/var/covers/small/10/1097928.jpg);"></div>
</div>
<h3>
<a title="View detailed information on Smashed (2012)" href="/movies/smashed/">Smashed</a>
</h3>
<span class="info">6 days ago</span>
</li>
<li class="listItem listItemSmall listItemMovie movie">
<li class="listItem listItemSmall listItemMovie movie">
</ol>
<span>
</div>
...
There are some libraries which could help you!
One I've used for the same purpose, a long time ago, is this: http://simplehtmldom.sourceforge.net/
I hope it help you!
follow steps to achieve this
STEP1:-
First get the contents using file_get_contents in a php file
ex: getcontent.php
<?php
echo file_get_contents("http://www.icheckmovies.com/movies/checked/?user=robinwatchesmovies ");
?>
STEP2:-
CALL the above script using ajax call and add the content to a visibility hidden field in the html.
ex:
$('#hidden_div').html(response);
html:-
<html>
<body>
<div id='hidden_div' style='visibility:hidden'>
</div>
</body>
</html>
STEP3:-
now extract the id what ever you want.
What you are asking for is called as web scraping ,I have done this a few months back, the process goes like this,
Make a HttpRequest to the site from which you need the content,check
the php class for it
Use a DOM parse library for handling the downloaded page (it would be in html),simple HTLM DOM would be a good choice
Extract your required information
Here are some tutorials for you,
HTML Parsing and Screen Scraping with the Simple HTML DOM
Library
Beginning web page scraping with php
SO Posts:
HTML Scraping in Php
And best of all Google is your friend just search for "PHP scraping"

Categories