Answer the question
In order to leave comments, you need to log in
How to break a php construct?
Hello, I'm making a plugin for WP and I need to change $text to assign html code and then loop through it through foreach, and I can't figure out how to break the php construction
, that is, do something like this
$text = ?> <div class="reviews">
<a href="" name="reviews"></a>
<div class="container">
<?php
Answer the question
In order to leave comments, you need to log in
A string can be specified in four different ways:
single quotes
double quotes
heredoc syntax
nowdoc syntax (since PHP 5.3.0)
You should probably write something like this:
$text = '<div class="reviews"><a href="" name="reviews"></a>';
foreach($reviews as $review) {
$text .= '<div class="container">' . $review . '</div>';
}
$text .= '</div><!--- /.reviews--->';
$text = "<div class=\"reviews\">
<a href=\"\" name=\"reviews\"></a>
<div class=\"container\"> ";
It looks like you are talking about HEREDOC, NOWDOC syntax:
$str = <<<EOF
<div class="reviews">
<a href="" name="reviews"></a>
<div class="container">
EOF;
$str = <<<'EOF'
<div class="reviews">
<a href="" name="reviews"></a>
<div class="container">
EOF;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question