I created a html site that has images that are links,
the images change on mouseover. I use a jquery function for this.
It all works perfect in HTML, but Im not sure how to combine the anchor and base_url to them when converting them to codeigniter.
I have been at this all day Id really appreciate any help, I am new to codeigniter I could not find any answers on their page or with a google search.
HTML code (works fine):
<a href="hotel.html">
<img src="img/image.png" hover="img/hoverimage.png" class="rollover"/>
</a>
I can get as far as linking the src image and can apply the class=rollover I just can not figure out how to add the hover="img/hoverimage.png"
<?php echo anchor('hotel', img('img/image.png'), array('class'=>'rollover' ));?>
Finally got it working. In short, I had to put the full address of the images rather than calling the base_url within an anchor. Probably a more accurate way of doing it but I spent so much time on this I am just happy it works....
<?php echo anchor('homepg/page/hotel', '<img src="http://localhost/websitefolder/img/image1.png" hover="http://localhost/websitefolder/img/imagehover.png" class="rollover"/>'); ?>
First, you don't need to use CodeIgniter's helpers to generate HTML. If you have working HTML already, then use it. Sometimes using CI's helpers can make the code more complicated, especially if other people need to figure out what it's doing.
To answer your question, the img() function accepts an associative array for the image's attributes. So you can specify the attributes similar to the anchor() function.
echo anchor('hotel', img(array('src' => 'img/image.png', 'class' => 'hover', 'hover' => base_url('img/hoverimage.png'))));
Note that this uses the base_url() function from the URL helper.
Related
I need to read a text file on a server and display its content in a blog post on Blogger. The text file is a result of a simple download counter and contains a number. The problem is the Blogger does not support PHP codes in a post. My current solution is to use OBJECT tag to call PHP script that displays the text file content with ECHO. It works. But the result is displayed inside a small frame and I can't apply CSS style to it or align it properly with the existing text. Is there another way? I understand it can be done with AJAX call but my scripting knowledge is basic and I wouldn't know where to begin. Help would be appreciated.
To display the result in the blog I used this code:
<p>File test.zip downloaded
<object type="text/plain"
data="http://example.com/statistics.php?dname=test"
width="30" height="30"></object> times</p>
EDIT: I have tried to follow #Toni suggestion but it only leads to more questions. Looks like Ajax call is way beyond my current level of knowledge. Sorry and thank you again.
Here is what I'm currently trying. I have moved the text that goes with the counter inside PHP file so the script now returns a string like "file has been downloaded 8 times" instead of just number "8". Also instead of OBJECT tag I'm using IFRAME.
<iframe src="http://example.com/mystats.php?dname=test"
frameborder="0" border="0" cells pacing="0" height="30"></iframe>
The iframe seems to be easier to style. If I can't figure out how to find which CSS is applied to a blog post and how to apply it to iframe, I can at the minimum mimic the style by using similar font.
You can use javascript with your blogger web-site.
Using javascript on your web-page, you can invoke a GET request to your PHP code and get the data you want, to display it on your web-page.
Below, there are links, to help you with this task:
How to invoke GET request in vanilla JavaScript
Invoking GET with jQuery
Use JavaScript to alter text dynamically
I made it work with JavaScript! Here is how. Server side PHP script reads and echoes a text file inside document.write().
<?php
$varcontent = #file_get_contents('yourtextfile.txt');
echo 'document.write("'.$varcontent.'")';
?>
The resulting string looks like this:
document.write("your text file content here")
Inside the Blogger post add the JavaScript code with the PHP script file as a source:
<script type="text/javascript"
src="http://example.com/yourfile.php">
</script>
Done! The content of your text file is displayed and styled with your current CSS.
So my school has this very annoying way to view my rooster.
you have to bypass 5 links to get to my rooster.
this is the link for my class (it updates weekly without changing the link)
https://webuntis.a12.nl/WebUntis/?school=roc%20a12#Timetable?type=1&departmentId=0&id=2147
i want to display the content from that page on my website but with my
own stylesheet.
i don't mean this:
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
or an iframe....
I think this can be better done using jquery and ajax. You can get jquery to load the target page, use selectors to strip out what you need, then attach it to your document tree. You should then be able to style it anyway you like.
I would recommend you to use the cURL library: http://www.php.net/manual/en/curl.examples.php
But you have to extract part of the page you want to display, because you will get the whole HTML document.
You'd probably read the whole page into a string variable (using file_get_contents like you mentioned for example) and parse the content, here you have some possibilities:
Regular expressions
Walking the DOM tree (eg. using PHPs DOMDocument classes)
After that, you'd most likely replace all the style="..." or class="..." information with your own.
Hi I am currently doing my website to pull all instagram photo into my web.
this is my code:
<div id="instafeed"></div>
<script type="text/javascript">
new Instafeed({
get: 'tagged',
tagName: 'awesome',
clientId: 'xxx',
image_size: 'standard_resolution',
}).run();
</script>
How do I get the url/path of the photo that i pulled inside my site?
Is it something about JSON? but i dont know what is it anyone can give me a hint?
Thanks!
You could use a webcrawler to pull the information you need from website.
Here is a nice tutorial. You need to specify the url and the desired html tag.
<?php
include_once('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('img') as $link)
{
echo $link->href."<br />";
}
Moreover you should look over cURL to improve you webcrawler.
EDIT:
#youaremysunshine
the code above is from the tutorial i suggested you look at. 'simple_html_dom.php' is a file that you need to download (you can find it in the tutorial) in order to use its functions.
So, after you include the file, you simply create a new simple_html_dom object and call the function load_file() with the desired url as a parameter. $html->find('img') looks for the <img> tag from the given page. Try to read the tutorial a few times and you may need to look up for part 2. Go to the website with the desired image and inspect element to see wich element you need to use for the find() function (the parameter may also contain the class/id of the searched element).
i've got the following problem. I've been moving a large amount of content by hand and while inserting images, i put the lightbox class on the tag - unfortunately for the images to properly work, they would need an anchor around them specifying the url to the full image size - for example
<img src="images/myimage.jpg">
All I've got now is :
<img src="images/myimage.jpg" class="lightbox">
Is it possible to automatically set an anchar around every image found inside a specific <div> element and also properly close it? I would need something like
foreach image in <div> prepend and append
Any solution in PHP or jQuery would greatly be appreciated!
You can use jQuery's .wrap() method:
$('div img').each(function(){
$(this).wrap('');
});
DEMO: http://jsfiddle.net/bztvw/
With jQuery use .wrap():
$.each($('img'), function(){
$(this).wrap('')
});
It would be better if you specify the container div of these images then only those images will be wrapped. Something like this:
$.each($('#lighboximgwrapper img'), function(){
$(this).wrap('')
});
Use RegExp
Pattern:
<img(.*)src="([\w\/\.]+)"(.*)>
Replace with:
<img src="$2" alt="" />
preg_replace PHP Function
Personally, I would fix the code generating the source. Just use the regex find/replace in your IDE and fix the source. Don't rely on some javascript or PHP hack to "fix" this mistake.
Hey guys I'm wondering how I would be able to grab only the first image on a page. I want to echo it somewhere else possibly as a variable.
well I have not attempted this before, but I found a website that looks like it gives a pretty good solution. if you are trying to copy the first image from a URL. http://phpsnips.com/snippet.php?id=61
hope that helps. :)
You use PHP's DOMDocument class to grab the page's source, use an XPath query with DOMDocument to get the first img tag, then grab its src attribute.
http://php.net/manual/en/class.domdocument.php
You can then use that to save the url, or download the file.