M
M
matros972018-02-16 19:42:47
PHP
matros97, 2018-02-16 19:42:47

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

But for some reason I get an error that I'm doing something wrong

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Stalker_RED, 2018-02-16
@Stalker_RED

A string can be specified in four different ways:
single quotes
double quotes
heredoc syntax
nowdoc syntax (since PHP 5.3.0)

php.net/manual/ru/language.types.string.php
Your construction doesn't correspond to any of the above, it's generally something strange.

B
Boris Syomov, 2018-02-16
@kotomyava

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--->';

N
Nikolai Chuprik, 2018-02-16
@choupa

$text = "<div class=\"reviews\">
  <a href=\"\" name=\"reviews\"></a>
    <div class=\"container\"> ";

E
eskanderdon, 2018-02-16
@eskanderdon

It looks like you are talking about HEREDOC, NOWDOC syntax:

$str = <<<EOF
<div class="reviews">
  <a href="" name="reviews"></a>
    <div class="container"> 
EOF;

or
$str = <<<'EOF'
<div class="reviews">
  <a href="" name="reviews"></a>
    <div class="container"> 
EOF;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question