Reputation:
How can you add this line of code in a
<a href='/<?=$value["content_url"];?>' class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true"><?=$value["content_title"];?><span class="caret"></span></a>
so eventually you get something like this:
if (1 == 1) {
echo "<a href='/<?=$value["content_url"];?>'
class="dropdown-toggle" data-toggle="dropdown" role="button"
aria-haspopup="true" aria-expanded="true"> <?=$value["content_title"];?>
<span class="caret"></span></a>";
} else {
echo "Nothing to see!"
}
Because you have multiple punctuations it will end the echo to quick..
Upvotes: 0
Views: 210
Reputation: 61
<a href='<?php echo $value["content_url"]; ?>' class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">
<?php echo $value["content_title"]; ?>
<span class="caret"></span>
</a>
try this
Upvotes: 0
Reputation: 1167
You can use print_f() function:
print_f("<a href='%s' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='true'><span class='caret'>%s</span></a>",
$value['content_url'],
$value['content_title']
);
or echo string in "string {var}":
echo "
<a href='{$value['content_url']}' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='true'><span class='caret'>{$value['content_title']}</span></a>
" ;
or use concritenate operand . 'string 1'.'string 2'
echo '
<a href="'.$value['content_url'].'" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true"><span class="caret">'.$value['content_title'].'</span></a>
' ;
but best way use template for example
index.php
function getContentUrl() {
return $value['content_url'];
}
function getTitle() {
return $value['content_title'];
}
include './template.phtml';
and template.phtml
<a href='<?php echo getContentUrl() ?>'><?php echo getContentTitle() ?></a>
Upvotes: 0
Reputation: 3579
if you want to actually print the PHP-code, you just have to escale your quotes
echo "<a href='/<?=$value[\"content_url\"];?>' class=\"dropdown-toggle\" data-toggle=\"dropdown\" role=\"button\" aria-haspopup=\"true\" aria-expanded=\"true\"><?=$value[\"content_title\"];?><span class=\"caret\"></span></a>";
if instead you want to print the values, you do not need the tags at all, but just have to concatenate the variables.
echo "<a href='/".
$value["content_url"].
"' class=\"dropdown-toggle\" data-toggle=\"dropdown\" role=\"button\" aria-haspopup=\"true\" aria-expanded=\"true\">".
$value["content_title"].
"<span class=\"caret\"></span></a>";
Upvotes: 1
Reputation: 355
if you want to print or echo php code than use concatenate
if (1 == 1) {
echo "<a href='".$value["content_url"]."' class='dropdown-toggle' data-toggle='dropdown' role='button'
aria-haspopup='true' aria-expanded='true'> '".$value["content_title"]."' <span class='caret'></span></a>";
} else {
echo "Nothing to see!"
}
Upvotes: 0
Reputation: 700
Format your string properly. Updated string.
if (1 == 1) {
echo "<a href=\"$value[content_url]\"
class=\"dropdown-toggle\" data-toggle=\"dropdown\" role=\"button\"
aria-haspopup=\"true\" aria-expanded=\"true\">$value[content_title]
<span class=\"caret\"></span></a>";
} else {
echo "Nothing to see!";
}
Inside double quoted string the php variables don't need to be quoted. Escape quotes by a backslash.
Upvotes: 1