Escape the double quotes in css inline style in php echo - php

I am sorry if this is duplicated but I could not find an answer to this situation. I am trying to escape the double quotes from the inline style in the PHP code.
<?php if (isset($ioTitle)){
echo "<div style='background-color: echo $params->get('colorbgt'); ;' class=\"ioTitleBox\"><h3 class=\"ioTitle\">";
echo $params->get("ioTitle"); echo "</h3></div>";
}

You can't put echo inside a string and expect it to be executed. You need to use concatenation.
echo "<div style='background-color: " . $params->get('colorbgt') . ";' class=\"ioTitleBox\"><h3 class=\"ioTitle\">";
You don't need to escape anything in the style for this. Also, you can use single quotes around the classes, to avoid those escapes.
echo "<div style='background-color: " . $params->get('colorbgt') . ";' class='ioTitleBox'><h3 class='ioTitle'>";

<?php if (isset($ioTitle)){
echo "<div style='background-color:". $params->get('colorbgt').";' class=\"ioTitleBox\"><h3 class=\"ioTitle\">";
echo $params->get("ioTitle"); echo "</h3></div>";
}
Is this how you want it?
You are echo-ing from inside an echo, you just need to concatenate that part into the existing echo statement.

Related

Adding Dynamic link with Spaces in variable

i am trying to create a dynamic link. $path="uploads/" and $fileName="Data Communication and Networking.pdf" which is retrieved from database. But the link gets created with href="upload/Data" ignoring the " Communication and Networking.pdf" part. How to add $fileName with spaces between the content.
$message=$row["message"];
$fileName=$row["filename"];
$date=$row["date"];
echo "<tr>";
echo "<td>".$Serial."</td>";
echo "<td>".$message."</td>";
echo "<td>Download</td>";
echo "<td>".$date."</td>";
echo "</tr>";
$Serial++;;
href value must consist in quotes. Place single quotes around your value.change your href as below:
echo "<td><a href='".$path.$fileName."'>Download</a></td>";
You can replace any space with %20
$CompletePath = str_replace(" ", "%20", $path . $fileName);
echo "<td>Download</td>";
//uploads/Data%20Communication%20and%20Networking.pdf is a valid URL
$path="/path";
$filename="/file with space.name";
echo "<td>Download</td>";
Will output:
`<td><a href=/path/file with space.name>Download</a></td>`
So you need to put the path between the quotes like this:
$path="/path";
$filename="/file with space.name";
echo "<td><a href='".$path.$fileName."'>Download</a></td>";

Syntax Error in concat echo statement and html code

Please help me to understand syntax of concat following
i want following code inside echo to understand concate
1--> <div class="alert echo $_REQUEST['error_id'];?>"\>
I try following code but getting syntax error that there is two echo..
2--> echo "<div class=\"alert" . echo $_REQUEST['error_id']; . "\">";
where mistake is that i cant get it... and i want two answer both using single quote and double quote
EDIT
Thank #Rizier123 now it working but css is not working as i have apply in calss="alert"
while using following code its working fine
<div class="alert echo $_REQUEST['error_id'];?>"\>
But after applying your code its not working..only text appear but background color is not comming nad boarder is also dissappear as below
class name is alert shows the status of login..
EDIT
Thanks again i just forget to put space after class name..
You don't need to write echo and ; again!
So this should work:
//echo with double quotes
echo "<div class=\"alert" . $_REQUEST['error_id'] . "\">";
//echo with single quotes
echo '<div class="alert' . $_REQUEST['error_id'] . '">';
Maybe you need to add a space if your class name includes spaces!(..."alert "...)
try this
echo '<div class=\"alert"' . $_REQUEST['error_id'] . '">';
You can do either 2 ways
1. PHP in HTML
<div class="alert<?php echo $_REQUEST['error_id'];?>">
2. HTML in PHP
echo "<div class='alert". $_REQUEST['error_id'] ."'>";
Or you can also do like
echo "<div class=\"alert". $_REQUEST['error_id'] ."\">";

JavaScript confirm box not appearing on PHP page

Can anyone see why this line in PHP doesn't work. The game card is deleted, but the confirm box does not appear for the user to okay or cancel.
echo "<a href='gamecard.php?selection=" . $row['gamedate'] . " onclick='return confirm('Delete game card?');'>Delete</a>";
Thank you.
You have single quotes inside of single quotes, you need to escape 'em. You also forgot the closing quote on the href attribute.
echo "<a href='gamecard.php?selection=" . $row['gamedate'] . "' onclick='return confirm(\"Delete game card?\");'>Delete</a>";
echo "Delete";
codepad example
echo "Delete";
will do it. HTML attributes, as a general practice, should be double quoted. JS strings should be single quoted.
You have some issues with missing quotes and using double quotes when you should be using singles (and vice/versa). This should do the trick.
echo "<a href='gamecard.php?selection=" . $row['gamedate'] . "' onclick='return confirm(\"Delete game card?\");'>Delete</a>";

add line break between 2 variables

I am echoing back these 2 variables in to a table, but wanted to know how to add a line break between these 2?
echo $row ['username'] . $row ['date_time'];
if you're printing an HTML output to your browser:
echo $row["username"]."<br />".$row["date_time"];
EDIT:
when printing to HTML - you better print the variables after passing them through htmlspecialchars function in order to avoid Cross-site-scripting (XSS), I'll do it this way:
echo htmlspecialchars($row["username"],ENT_QUOTES)."<br />".htmlspecialchars($row["date_time"],ENT_QUOTES);
if you want to print it to a file or something similar:
echo $row["username"]."\n".$row["date_time"];
you can always echo normal html from php.
echo "<div id=\"mydiv\"> Div content goes here </div>";
note the backslashes for double quotes wrapping mydiv to escape them.
so you can add a tag in between them to get a new line.
echo $row["username"] . "<br />" . $row["date_time"];

PHP convert javascript when echo

I have following PHP echo statement:
echo "<td><a href='delete-news.php?deleteID=".$id." onclick='return confirm('Really delete?');'>Delete</a></td>";
which is convert to html as:
<td class="last-td nth-8"><a delete?');'="" confirm('really="" return="" href="delete-news.php?deleteID=5 onclick=">Delete</a></td>
As you can see something has gone wrong?
What is the problem? I have already tried swaping " " for single ' '.
Your have double single quotes in the onclick statement, try confirm(\'Really delete?\') instead.
You have forgot ' after href. Use it like
Double quotes:
echo "<td>Delete</td>";
Single quotes:
echo '<td>Delete</td>';
You have href not closed. Also, your 'Really delete' cause trouble too. Try this
echo "<td><a href='delete-news.php?deleteID=$id' onclick='return confirm(\"Really delete?\");'>Delete</a></td>";

Categories