I have a php script I want to echo some html with. I keep getting this error:
Parse error: syntax error, unexpected T_ECHO
echo "<a onClick=\"" window.location.href='test.php'; "\" class='container'>test</a>";
Try this:
echo "<a onClick=\"window.location.href='test.php'\" class='container'>test</a>";
You aren't escaping the double quotes correctly. Each double quote that you want to escape should be written as \" . Looks like you were trying to open and close an escaped block or something.
echo "<a onClick=\"" window.location.href='test.php'; "\" class='container'>test</a>";
vs
echo "<a onClick=\"window.location.href='test.php';\" class='container'>test</a>";
Related
I echo out an image like that:
$newString = $thumbPre.'profilemain'.$thumbPost;
echo "<img src='http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error'>";
Now i want the image as a background-image, i tried it like that, but it doesn´t work:
echo '<div style="background-image:url('http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error');"></div>';
you need to use backslashes for nested apostrophes
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\' alt=\'error\');></div>';
Firstly, remove alt='error' because background-image does not have an alt parameter, img does (you probably thought you could use that from your original code). In trying to use that, your background will not show up.
And your background won't show unless you have content inside that div. I've added Content as an example.
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\');">Content</div>';
You either have to escape the encapsulating quotes, or remove them altogether.
echo '<div style="background-image:url(http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.');">Content</div>';
Error reporting would have also thrown you a parse error such as:
Parse error: syntax error, unexpected '' alt='' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'
http://php.net/manual/en/function.error-reporting.php
This is going to look super confusing but you need to 1, escape the quotes and 2, concatenate your path within that,
let me give you an example. I misread a bit of the question but this will serve you well moving forward especially for cleanliness sake
here is an example:
$imagePath ='PATH TO IMAGE HERE';
echo '<div style="background-image:url(\'' .$imagePath. '\')" >STUFF HERE </div>';
Getting error in this code...please help... i have changed it also like....
echo "<td>" Download"</td>";
or
<td><a href='get_file.php?id={$row['id']}'>Download</a></td>
still getting the error.
This should work for you:
(You don't concat the strings correctly and you forgot quotes for the href tag)
echo "<td><a href='get_file.php?id=" . $row['quote_id'] ."'>Download</a></td>";
Concatenation is your friend when outputting HTML.
echo '<td>Download</td>';
I usually try to put the single quotes on the outside and the double quotes on the inside because it's easier for me to manage.
I might have a syntax error or something but I don't see nothing.
<select id="cd" name="cd">
<?php
while($row=mysql_fetch_array($cdresult)) {
echo "('<option value='$row['Poblacion']'></option >'.'<br />)";
}
mysql_close($link);
?>
</select>
On the echo line, I have the error :
[error] [client] PHP Parse error: syntax error, unexpected
T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or
T_NUM_STRING in /var/www/slimtest/views/nuevo.php on line 89
Maybe you can help, because I don't see the error D"=
When using array variables inside of strings it's usually better to use the complex syntax:
echo "('<option value='{$row['Poblacion']}'></option >'.'<br />)";
Alternatively you can remove the quotes in the array key:
echo "('<option value='$row[Poblacion]'></option >'.'<br />)";
PHP String Variable Parsing
This should work:
<select id="cd" name="cd">
<?php
while($row=mysql_fetch_array($cdresult)) {
echo "<option value=".$row['Poblacion']."></option><br/>";
}
mysql_close($link);
?>
</select>
Try changing echo line to this:
echo '<option value="' . $row['Poblacion'] . '"></option >';
This line is a mess
echo "('<option value='$row['Poblacion']'></option >'.'<br />)";
First off, you can't use other characters around an <option> tag (the <br> tag is meaningless there). And then you leave the text of the tag blank. Finally, you're using double quotes around the whole thing, leaving PHP to try and interpret it. My bet is you're trying to do this instead.
echo '<option value="' . $row['Poblacion'] . '">' . $row['Poblacion'] . '</option>';
This will generate a proper tag AND populate it with the text of your field as well (so users can see what they're selecting). The way you had it, even if it were proper HTML, you'd have a dropdown of nothing but blank entries.
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.