How do I go about using an image as a link in php? I have never put two html elements together in one echo so it's kinda new for me.
Here's my code:
htmltest.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<?
require("includes/conn.php"); //link to the database
?>
<html>
<title>HTML with PHP</title>
<body>
<?php
echo "<img src="homelogo.jpg" />";
?>
</body>
</html>
That's my code. I get the following error:
PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home6/dreamsm2/public_html/htmltest.php on line 11
Can anyone tell me what I'm doing wrong? Any help would be appreciated.
Change the line to:
echo '<img src="homelogo.jpg" />';
OR
echo "<img src=\"homelogo.jpg\" />";
The problem, as the error somewhat suggests, is that the PHP interpreter can't figure out where your string is supposed to start and end. Using \" escapes the quotes. Using ' around the string gives a unique string delimiter around the string, so you are free to use double quotes inside.
Note, if you needed both single and double:
echo '<img src="homelogo.jpg" />';
You can also use ' instead of " for strings, e.g.
This works: echo '"Hello!"'; => "Hello!"
This wont work: echo "'Hello'";
SIMPLY DO THIS:
echo '<img src="Downloads_clip_image010.jpg" />';
For WordPress
<div class="floatLeft">
<a href="http://trophydevelopers.com">
<img src="<?php bloginfo('template_url'); ?>/images/powered-by.png">
</a>
</div>
Related
I want display my button if it have isset($_GET). I am trying to do like this.
<?php if(isset($_GET['project_id'])){
echo '<div class="add_btn_primary"> Project Users </div>';
}?>
its giving me error like
Parse error: syntax error, unexpected 'project_id' (T_STRING), expecting ',' or ';' in C:\xamppp\htdocs\mayank\add_project.php on line 101
I am not getting idea what I should do for echo project_id in div. Let me know if someone can help me for that.
Thanks
Thats incorrect to use echo inside another echo and how can you start a new php tag without closing the first.
The correct way is to concatenate the variable along the string passed in echo, here is how
<?php if(isset($_GET['project_id'])){
echo '<div class="add_btn_primary"> Project Users </div>';
}?>
instead of breaking the php tags break the ' quotes to concatenate the value in the string.
Why do you need again tag inside echo just use it as below:
<?php
if(isset($_GET['project_id']))
{
echo ('<div class="add_btn_primary"><a href="manage_project_users.php?project_id='.$_GET["project_id"].'>Project Users</a></div>');
}
?>
I have the following code:
echo "<script type='text/javascript'>
iframe0document.getElementById('jform_articletext').value = '<?php echo \"<p align='center'><iframe src='aufgaben/'+cookieValue+'/'+cookieValue+'.html' width='322' height='497' frameborder='0'></iframe></p>\";?>';}</script>";
but it has a problem with the quotes, I tried almost everything but it says always:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /usr/www/users/mathea/joomla/plugins/content/DirectPHP/DirectPHP.php(58) : eval()'d code on line 118
Ok the question should be changed to php nesting in php. I need a way to negate the offect of the php nesting like it's possible for quotes with \"
Updated
You made PHP tags within echo. That's pretty wrong!
As I understand OP:
$text = htmlentities('<?php echo \'<pre><p align="center"><iframe src="aufgaben/"+cookieValue+"/"+cookieValue+".html" width="322" height="497" frameborder="0"></iframe></p></pre>\'; ?>');
echo "<script type='text/javascript'>
iframe0document.getElementById('jform_articletext').value = ".$text.";
</script>";
You need htmlentities function to encode characters to their html equivalents and print out php tags az plain text.
But you are already in "php mode"!
Why you reopen php tag on
'<?php echo
?
Then, what is "iframe0document.getElementById"?
<html>
<head>
<title>Find my Favorite Movie!</title>
</head>
<body>
<?php
echo “<a href='localhost/moviesite.php?favmovie=Inception'>Inception</a>";
?>
</body>
</html>
Getting the following error for the above code.
Parse error: syntax error, unexpected 'href' (T_STRING), expecting ',' or ';' in C:\xampp\test\movie1.php on line 7
As you can see you have a litteral mistake in
echo “<a href='localhost/moviesite.php?favmovie=Inception'>Inception</a>";
couse “ != "
change it to:
echo "<a href='localhost/moviesite.php?favmovie=Inception'>Inception</a>";
echo 'Inception';
Should do the trick for you
You have an copy and past error try this:
echo "<a href='localhost/moviesite.php?favmovie=Inception'>Inception</a>";
You are using by misstake a wrong quote “ instad of ". Often are quotes replaced wrong by some CMS like Wordpress. So you need to check double that you use the right quotes.
I am currently trying to create a shopping cart for my website and I have images of products stored in a database and I want to include them within <img src> . By putting $get_row[imagesrc] within the src. I need to know the correct way to add it to the below code as I dont fully understand the ' and . tags
echo '<p>'.$get_row['name'].'<br/>'.$get_row['description'].'<br/>'.$get_row['imagesrc'].
'<br/>£'.number_format($get_row['price'],2).'Add</p>';
This should achieve what you're looking for:
echo '<p>'.$get_row['name'].'<br/>'.$get_row['description'].'<br/><img src="'.$get_row['imagesrc'].'" /><br/>£'.number_format($get_row['price'],2).'Add</p>';
The ' character defines a string literal when it is wrapped around a series of characters.
The . character is used for concatenating strings for output or storage.
echo '<p>'.$get_row['name'].'<br/>'.$get_row['description'].'<br/><img src="'.$get_row['imagesrc'].'"><br/>£'.number_format($get_row['price'],2).'Add</p>';
. concatenates two strings, and ' is wrapped around a string.
so
echo 'Hello '.'World'; // Shows Hello World
I'd split yours up to make it easier to read:
echo '<p>';
echo $get_row['name'].'<br/>';
echo $get_row['description'].'<br/>';
echo '<img src="'.$get_row['imagesrc'].'" /><br/>';
echo '£'.number_format($get_row['price'],2);
echo 'Add';
echo '</p>';
But it all looks OK.
echo '<p>'.$get_row['name'].'<br/>
<img src="'.$get_row['imagesrc'].'" alt="'.$get_row['name'].'"><br/>
<br/>£'.number_format($get_row['price'],2).'
Add</p>';`
echo '<img src="'.$get_row['imagesrc'].'">';
Try that.
A specific answer has been given:
echo '<img src="'.$get_row['imagesrc'].'">';
Nonetheless, it's worth adding that you should:
You should escape output - with htmlspecialchars() or otherwise.
echo '<img src="' . htmlspecialchars($get_row['imagesrc']) . '">';
Read the documentation on PHP Strings.
Check out this way of including PHP in your HTML. It's much easier to read and maintain. The last line in the paragraph is your image tag.
<p>
<?php echo $get_row['name']; ?><br/>
<?php echo $get_row['description']; ?><br/>
<?php echo $get_row['imagesrc']; ?><br/>
£<?php echo number_format($get_row['price'],2); ?>
Add
<img src="<?php echo $get_row['imagesrc']; ?>" />
</p>
I'm going crazy trying to echo an <img> tag.
I want to add this simple string "/uploads/" before $photo->name.
Here is my echo: echo '<img src="'.$photo->name.'"/>';
Thanks for any help.
Not sure if I completely understand, but try this:
echo '<img src="/uploads/'.$photo->name.'"/>';
Here you go:
echo '<img src="/uploads/'.$photo->name.'"/>';
Or:
echo '<img src="' . '/uploads/' . $photo->name.'"/>';
Or:
echo '<img src="' . "/uploads/" . $photo->name.'"/>';
echo '<img src="/uploads/'.$photo->name.'"/>';
How about
echo '<img src="/uploads/'.$photo->name.'"/>';
... unless I'm missing something?
two ways to use echo tag
1st : one is double quotes which use for out put of strings
echo "your name is".$name //here name is variable
2nd : one is single quotes in which you can use all html tags here is the example
<?php
$name="Adil";
echo $name;
for($i=0;$i<44;$i++)
{
echo($i.'<br>') ;
if($i==10)
{
echo ' <table border=3> <tr><td><h1>its image </h1><img src="examp.png" alt="loading" /><td><td>hello</td><tr></table>';
}
}
?>
here i am using multiple tags in echo using
single quotes
if put double quotes then you will see following error
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\Untitled2d.php on line 21
here is the output