Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way you are looping through the array, using :</p> <pre><code>foreach($array as $var =&gt; $content) { // ... } </code></pre> <p>makes me think you should use an <strong>associative array</strong> for your <code>$array</code>.</p> <p>i.e., it should be declared this way :</p> <pre><code>$array = array("HEADER" =&gt; "Welcome to ".NAME."'s website!"); </code></pre> <p><br> And, as a demonstration, here's an example of code :</p> <pre><code>$template = &lt;&lt;&lt;TPL Hello, World ! {HEADER} And here's the content ;-) TPL; define("NAME","Site Name"); $array = array("HEADER" =&gt; "Welcome to ".NAME."'s website!"); foreach($array as $var =&gt; $content) { $template = str_replace("{" . strtoupper($var). "}", $content,$template); } var_dump($template); </code></pre> <p>And the output I get it :</p> <pre><code>string 'Hello, World ! Welcome to Site Name's website! And here's the content ;-)' (length=73) </code></pre> <p>Which indicates it's working ;-) <br><em>(It wasn't, when <code>$array</code> was declared the way you set it)</em></p> <p><br> When using this :</p> <pre><code>$array = array("HEADER","This is the header"); var_dump($array); </code></pre> <p>You are declaring an array that contains two items :</p> <pre><code>array 0 =&gt; string 'HEADER' (length=6) 1 =&gt; string 'This is the header' (length=18) </code></pre> <p><br> On the other hand, when using this :</p> <pre><code>$array = array("HEADER" =&gt; "This is the header"); var_dump($array); </code></pre> <p>You are declaring an array that :</p> <ul> <li>contains only one item</li> <li>"HEADER" being the key</li> <li>and "This is the header" being the value</li> </ul> <p>Which gives :</p> <pre><code>array 'HEADER' =&gt; string 'This is the header' (length=18) </code></pre> <p><br> When using <code>foreach ($array as $key =&gt; $value)</code>, you need the second one ;-)</p> <p><br> And, purely for reference, you can take a look at, in the manual, the following pages :</p> <ul> <li><a href="http://fr2.php.net/manual/en/language.types.array.php" rel="nofollow noreferrer">Arrays</a></li> <li><a href="http://fr.php.net/manual/en/control-structures.foreach.php" rel="nofollow noreferrer">foreach</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload