display a captcha image in my page - php

i have to get the captcha image from a web page. for that i use phpquery and dom file like the following..
<?php
include 'phpQuery-onefile.php';
$html = file_get_contents("http://who.godaddy.com/whoisverify.aspx?domain=nettantra.com&prog_id=godaddy");
$pq = phpQuery::newDocument($html);
print $pq->find('img#whoisverify_ctl00_cphcontent_ctlcaptcha_CaptchaImage')->attr('src').'<br/>';
?>
<img src="<?php print $pq->find('img#whoisverify_ctl00_cphcontent_ctlcaptcha_CaptchaImage')->attr('src'); ?>" alt="captcha_image" />
<?php
echo '<br />';
require_once('../simple_html_dom.php');
$html = file_get_html('http://who.godaddy.com/whoisverify.aspx?domain=nettantra.com&prog_id=godaddy');
foreach($html->find('img') as $element) {
echo $element.'<br/>';
// echo $element->src, "\n";
}
?>
now, i have only the problem that it fetch the source, but cant get the image. is that impossible to save the captcha image in my page ?

Change img sourse like this
<img src="http://who.godaddy.com/<?php print $pq->find('img#whoisverify_ctl00_cphcontent_ctlcaptcha_CaptchaImage')->attr('src'); ?>" alt="captcha_image" />

Related

Trying to use in line styling in the middle of a PHP echo

Is there anyway I can get in-line styling within a PHP echo statement. I want to set the height and the width of an image, as when I try to apply the height and `width externally it makes no difference as the image loads before the style sets in.
I have tried this but doesn't seem to be making any difference what so ever...
<p><b>Profile Picture: </b>
<?php
$picture = $row['imagePath'];
if (empty($picture)){
echo "<img src='profiles/no-image.png' 'width=500' 'height=600' >";
} else {
echo "<img src='".$row['imagePath']."' 'width=500' 'height=600' >";
};
?></p>
That doesn't work because you are not setting the quotes right.
This should do the trick:
echo "<img src='profiles/no-image.png' width='500' height='600' >";
You can apply styles the same way:
echo "<img src='profiles/no-image.png' style='width:500px;height:600px;'>";
Here is an alternative. Use PHP like a template engine. This approach does not use echo statements to output HTML. Instead, dynamic elements are introduced as needed.
<p><b>Profile Picture: </b>
<?php
$picture = $row['imagePath'];
if (empty($picture)) :
?>
<img src="profiles/no-image.png" width="500" height="600" >
<?php else : ?>
<img src="<?= $row['imagePath'] ?>" width="500" height="600" >
<?php endif ?>
</p>

HTML - PHP echo image

How do I properly echo images combining HTML and PHP? $offer['picture'] has link saved as example.com/picture.png. I've tried many different options, but nothing works. Can anyone help me out?
foreach($json['offers'] as $offer) {
$image = $offer['picture'];
?>
<img src="<?php echo $image ?>">
<?php
}
If there is only example.com/picture.png in $offer['picture'], problem is that images linked incorrectly. You should add http:// before image link to make browser sure you are loading image by absolute path.
foreach($json['offers'] as $offer) {
$image = $offer['picture'];
?>
<img src="http://<?php echo $image ?>">
<?php
}
Well it depends on your directory structure.
suppose your images are in example.com/assets/images/photo-1.jpg
your code should be
<?php foreach($json['offers'] as $offer) {
$image = $offer['picture']; ?>
<img src="http://www.example.com/assets/images/<?php echo $image; ?>">
<?php } ?>
In fact, you need to concatenate or hard code the path and image name will be appended dynamically.
Try this syntax,
<?php
foreach($json['offers'] as $offer) {
$image = $offer['picture'];
echo "<img src='$image' />";
}
?>

I'm trying to echo an image in a PHP variable in CodeIgniter

Hello I'm trying to echo an image on a view page in CodeIgniter but nothing is displayed on the page.
Here I'm making the variable:
<?php $image = "<img src='../../images/stoel.jpg' alt='img' />"; ?>
And here I'm trying to echo the image:
<img src="<?php echo $image;?>">
Intro
This is the most basic php, so what's the addition of this question? Please read the basics of echo here: http://php.net/manual/en/function.echo.php (Example 1).
Learn the basics first!
Solution
1. Assign full html tag to variable and echo full html:
<?php
$image = '<img src="../../images/stoel.jpg" alt="Foo">';
echo $image;
?>
2. Or assign image path to variable and echo concat string:
<?php
$path = '../../images/stoel.jpg';
echo '<img src="' . $path . '" alt="Foo">';
?>
3. Or assign image path to variable and echo only this with php:
<?php
$path = '../../images/stoel.jpg';
?>
<img src="<?= $path; ?>" alt="Foo">
You are inserting full Image tag into src attribute.
<?php $image = "<img src='../../images/stoel.jpg' alt='img' />"; ?>
and
<?php echo $image; ?>
or
<?php $image = "../../images/stoel.jpg"; ?>
and
<img src="<?php echo $image;?>">
<?php $image = "<img src='../../images/stoel.jpg' alt='img' />"; ?>
you try like this
<?php echo $image; ?>
You are already assign full image code in variable so you just need to print your variable:
<img src="<?php echo $image;?>">
To
<?php echo $image;?>
Make sure your images out side of the application folder then you can do something like
application
images
images > stoel.jpg
system
index.php
Use Base url from the url helper
<img src="<?php echo base_url('images/stoel.jpg');?>" />
Make sure you have set the base_url in config.php
$config['base_url'] = 'http://localhost/yourproject/';
You can also use HTML Helper img();
I think this is what you mean. Since you are echoing inside the src attribute, you do not need to store the whole <image>, just the path will do.
<?php
$image = "../../images/stoel.jpg";
?>
<img src="<?php echo $image;?>">

How to style the Simple_HTML_DOM output

I'm getting images and their url with the following code using Simple HTML DOM Parser:
<?php
include_once('simple_html_dom.php');
$url = "http://www.tokyobit.com";
$html = new simple_html_dom();
$html->load_file($url);
foreach($html->find('img') as $img){
echo $img . "<br/>";
echo $img->src . "<br/>";
}
?>
But the output doesn't look so nice:
(source: netdna-cdn.com)
So how can I style the outputs in CSS like with adding a class to each image and it's src.
My CSS:
.image-and-src {
border: 2px solid #777;
}
So how can I add that class? : image-and-src
foreach($html->find('img') as $img){
echo '<div class="img-and-src">';
echo $img . "<br/>";
echo $img->src . "<br/>";
echo '</div>';
}
The two lines added to the code wraps the echo'd content in a div with your class while it loops.
Now you have the possibility to also wrap the text in a span, styling them both seperately.
If you want to add the class to just the image without styling the text, you could try #Ajeet Manral's answer :)
try this
foreach($html->find('img') as $img){
echo $img->src . "<br/>";
echo '<img src="'.$img->src.'" width=100% height=100px><br/>';
}
How about trying to make your own template
a template file
<!DOCTYPE html>
<html>
<head>
<title>Your title</title>
</head>
<body>
<h1>Somebody's images</h1>
<?php foreach($html->find('img') as $img) { ?>
<!-- put some pretty looking html here -->
<?php } ?>
<body>
</html>
if you don't know about templates, then I suggest some research on the subject

How to opening images on the same page?

I have an album plugin (php) that creates thumbnails for my images in one page and when i click on images opens each image in a new page.
Is there a way to opening images on the same page of thumbnails?
This is my code of thumbnails:
<div class="thumbs">
<?php foreach (wppa_get_thumbs() as $tt) : global $thumb; $thumb = $tt; ?>
<img src="<?php wppa_thumb_url(); ?>" alt="*" />
<?php endforeach; ?>
</div>
and this is the code of specific photo:
<?php } else if (wppa_page('single')) { // if is showing a specific photo ?>
<a href="<?php wppa_photo_url(); ?>"><img src="<?php wppa_photo_url(); ?>" alt="<?php wppa_photo_name(); ?>" class="big" <?php echo wppa_get_fullsize(); ?> />
</a><br />
<?php } ?>
And this is the function that creates links:
// get link to photo
function wppa_photo_page_url($return = FALSE) {
global $thumb;
$url = get_permalink() . wppa_sep() . 'album=' . $_GET['album'] . '&photo=' . $thumb['id'];
if ($return) {
return $url;
} else {
echo $url;
}
}
I tried to remove the link code but does not work.
The act of opening a link in a new window is usually associated with the "target" attribute of an anchor. For example, this would put links in new windows:
text
But the code you've pasted above does not appear to include target attributes in , so I suspect the behaviour is controlled in your CSS, which you didn't include in your question.
Check your CSS files, and look for "target". The W3C has published documentation that describes how this works.
It's actually very easy to do using plain javascript's Image object. You can have a function that does something like this:
function load_image(image_path)
{
var image = new Image();
image.src = image_path;
return image;
}
You can pull the url to the image from the link that they click on.
Then, append that image to a hidden div you have and make it visible. If you're using jQuery:
var image = load_image("/path/to/your/image.jpg");
$(image).appendTo("#your-image-div");
$("#your-image-div").show();
This is untested, but should work.
You could use a jQuery plugin like Lightbox to pop the content dynamically over the current page.

Categories