I am calling my makewindows function from a PHP file like so:
echo "Click for full description </p>";
This generates correct html, which results in a popupwindow containing the html from $html. For example(most of the html has been snipped):
Click for more
Now, I want to make an image above the link clickable, to display an image instead of html, using the same method.
I made an $imagehtml variable in php like so:
$imagehtml = "<img src='".$imageSrc."' >";
$imageSrc is the result of another method, but is always without fail a valid url for an image
passing $imageHtml to makewindows should work(the fact that it is not standards complaint html is irelivant, at least as to why what I am trying is failing. The same single line of html in a standalone html file displays in every browser fine.)
this results in the following html:
<a href="#" onclick="makewindows(<img src='removed.jpg' >); return false;">
<img src="removed.jpg" width="250" height="250"></a>
This completely fails. It has nothing to do with the image path, as no window is created at all. All I am doing is changing the variable passed, surely the window should still be created, regardless of the contents of the html?
this fails even if trying to pass about:blank, for example defining imagehtml as follows:
$imagehtml = "about:blank";
results in:
Click for full description
yet still no window.
You want something like this:
$str = '<img src="...">';
echo '<a href="#" onclick="makewindows('
. htmlspecialchars(json_encode($str))
. '); return false;">Click for full description</a></p>';
This will do the correct encoding / escaping.
You’re probably doing something wrong.
Let’s say you want to pass this HTML to a JavaScript function call inside an HTML attribute:
<img src="removed.jpg" width="250" height="250">
Then doing this is enough:
$html = '<img src="removed.jpg" width="250" height="250">';
echo 'Click for full description</p>';
The var_export function converts the value into an (PHP) equivalent expression and the htmlspecialchars function finally converts the HTML meta characters into character references.
This might not be the most elegant way, but it works.
Related
I'm trying to open the user_url within an iframe on a private user page in Wordpress.
I put the following code into a snippet:
<?php echo get_the_author_meta('user_url',$userID); ?>
When I use the short code on the user page it does display the user URL, I can also use it in an hyperlink like this:
link text
But when I put the short code into an Iframe the short code does not change into the URL anymore.
<iframe src="[cmruncode name='dash']" height="300" width="300" title="Iframe"></iframe>
Does anyone knows why this is not working and know a solution?
Thanks Peter
If you are using WordPress shortcode then you have to call shotcode using function do_shortcode.
You can try this one
<iframe src="<?php echo do_shortcode( '[cmruncode name="dash"]' ); ?>" height="300" width="300" title="Iframe"></iframe>
And I'm not sure why anchort text display right output. That's weird.
Anyway if you used do_shortcode to output your shortcode then it will work every place.
This only works when I put it directly into the template, in that case no snippet-shortcode is needed at all. But the content needs to be hidden when the user is logged-out.
Normally the plugin "client portal" that I use should take care of this
but it has a content block that does not support PHP and also does not render the php snippet that I made.
Any suggestions?
The solution was to put the iframe code completely into a snippet.
Like this:
<iframe src="<?php echo the_author_meta('user_url',$userID); ?>" height="2400" width="100%" title="Iframe"></iframe>
I have PHP code that generates HTML code which makes a grid of images. The images are taken from links that are generated for each new image, I also add 133x100 at the end of the image link to resize it on the page. My problem is that a seemingly random selection of images won't display, and I just get a broken image symbol. For example:
This is a link to an image that is generated on my page and is displayed.
This is a link to an image that will not be displayed.
I am only allowed to post 2 links, but removing the %20.%20/133x100 from the end of the last link will show what the picture should be.
Here is the part of the code for the image source:
function display_images(){
//This cycles through each image and displays it as HTML
while($row = $item->fetch()){
Echo "`<img src= '$link[Image_Link] . /133x100' />`"
}
}
It is then called here in a class which puts the images in a grid:
<ul class="rig columns-4">
<?php
display_images();
?>
</ul>
Seemingly about every 2/20 images won't work, and seeing all the links are in the same format, I don't understand why they won't work, and it just seems random.
EDIT: I have noticed that the links that work have 62fx62f at the end of them before the added %20.%20/133x100. If I add it to the raw link in the right place, it makes the image work. But using that generated link, the image still won't load on the page. So using a link with a working image will not work on the page. (This is the same with the raw link without %20.%20/133x100, that links to an image but also won't work on the website)
When visiting the links, the urls look like this:
http://www.example.com/image/randomcharacters%20.%20/133x100
The links work without the %20.%20 at the right dimensions, like so:
http://www.example.com/image/randomcharacters/133x100
This leads me to believe that it may work if you try using the following for the image source instead:
<img src= '$link[Image_Link]/133x100' />
The full code would look like this, for the while function:
while($row = $item->fetch()){
echo "<img src= '" . $link['Image_Link'] . "/133x100' />";
}
I am not aware of steamcommunity much but from the looks of it, i think you should try this.
Instead of putting
. /133x100
Use
/133fx100f
So your URLs would be
while($row = $item->fetch()){
echo "<img src= '" . $link['Image_Link'] . "/133fx100f' />";
}
Just did some trial and error and found out. No explanations for this though!!
I have an application that returns data to a PHP/HTML file but the issue is it can call my application many times per page load:
An example HTML file with my calls only asking for images:
<img border="0" alt="" src="http://mydomain.com/test/index.php?element=1"></img>
</br>
<img border="0" alt="" src="http://mydomain.com/test/index.php?element=2"></img>
</br>
<img border="0" alt="" src="http://mydomain.com/test/index.php?element=3"></img>
</br>
This works fine every time and all of the images are returned, however my trouble starts when I want to return text/html.
The server side code works fine:
header('Content-type: text/html');
ob_start();
echo $filepath;
ob_flush();
ob_end_clean();
$filepath contains some text or HTML such as, "Check out our <strong>NEW</strong> offers!"
All I want is to return the HTML text and allow it to be embedded within the page so that if they want:
<h1>Check out our <strong>NEW</strong> offers!</h1>
or
<p>Check out our <strong>NEW</strong> offers!</p>
It will work fine.
The problem is, which HTML Tag should I use to call for the data in the same way I use <img> for images?
I have tried <object>, `
` etc... but these are no good as all I want is the raw HTML data returned.
Using the Javascript load() is not good as it relies on the web page builder creating a function call for every time they want to get data.
You can't do it with HTML, you could use jQuery + AJAX.
You have to use Ajax. you cannot do it in html.
You can output it with PHP and then if you update the file it will update site wide without making changes everywhere. Is there a reason you want to do it this way and not just insert the code manually? This could cause problems with the caching of your pages depending on how dynamic they are.
newOffers.php
<?php
echo '<h1>Check out our <strong>NEW</strong> offers!</h1>';
?>
Then in your site source:
<p>Blah blah blah...</p>
<?php include 'newOffers.php'; ?>
<p>Click our new offers link above</p>
You can use an <iframe> for this, but this is not really ideal as the resizing is not done automatically.
Alternatively you can indeed use Ajax to change the code.
Either way: think about your reason for wanting to include the HTML like this instead of just returning this html code with the original return?
I am trying to call images in this function, but they all come up as question marks. Could anyone tell me what I did wrong?
if(!$currentvotes) $currentvotes = 0;
echo '<div class="vote vote'.$id.'"><span>'.$currentvotes.'</span>';
if($user_ID && !$alreadyVoted) echo '<br /><a post="'.$id.'" user="'.$user_ID.'"><img src="/images/thumbsup.png" WIDTH=25 HEIGHT=25></a>';
if($user_ID && $alreadyVoted) echo '<br /><span class="voted"><img src="/images/thumbsup.png" WIDTH=25 HEIGHT=25></span>';
echo '</div>';
if(!$user_ID) echo '<div class="signup"><p><a style="color:#4ec1f3;" href="'.get_bloginfo('url').'/wp-login.php?action=register"><img src="/images/thumbsup.png" WIDTH=25 HEIGHT=25></p></div>';
}
I am trying to call images in this function
As in the comments:
You can't 'call' an image. You can call functions, methods,
procedures, code but images are data and can't be 'called'. – Patashu
[...] they all come up as question marks
Right click on those question marks: choose "open image in new window". You should see a new page with a 404 error. Look at the link of that page: that's the path where your image is supposed to be (if you're getting a 404 error it simply means they are not there). Create the folder images and upload the file thumbsup.png. Now reload the page.
I suppose the path you are using has to be absolute eg (http://.../images/myimage.jpg) instead /images/myimage.jpg. This is common issue when you write custom code (don't use standard framework) and use .htaccess to rewrite urls.
You can set basepath as constant so you can easy change it if you switch domains.
define("BASE_PATH", "http://mydomain.com");
and then in code use it:
BASE_PATH."/images/myimage.jpg"
Or use base tag in your head in html
<base href="http://www.yourdomain" target="_blank">
And as Saturnix said in his answer you should have folder named "images" and filename you put in src.
If an image can't be found in the location you specify in your HTML, the browser will display a broken image link marker, maybe like one of these;
Chrome
IE10
Firefox 10
Each browser has its own marker. Maybe your browser uses a question mark to indicate a broken image link.
This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
Want to render an image without saving it to disk using PHP GD libs
The image cannot be displayed because it contains errors.
I'd like to call a function that make a image trought the img src tag. Is it possible?
I mean : instead of call <img src="path/file.php" /> I'd like to do somethings like <img src="function()" />
PHP is server side; It can generate either a base64_encoded image result which can be placed as an image, or you can point to a php script that will generate an image. But, regarding client side, it won't work.
So, you could do the following:
// the browser will make a call to your generator to render an image back
echo '<img src="myimagegenerator.php" />';
// src will be something like "data:image/png;base64,..."
echo '<img src="'.generateImage().'" />';
In HTML5 you can put the base64 encoded image source in an image tag. You will just need a function to return that.
function getImage($file){
return 'data:image/gif;base64,' . base64_encode(file_get_contents($file));
}
Your img tag:
<img src="<? echo getImage('path-to-image.gif'); ?>" />
No.
However, you can use the URL "thispage.php?makeimage=1" and call the function and output an image if $_GET['makeimage'] contains 1.