Jump to content

Recommended Posts

Hello,

 

I seem to have a big problem with coding my site, and it has to do with the While loop.

 

 

I have a page called template.php Which looks something like

 

<?php

$temp = '
HTML HERE


{_NEWS_} << This is where the loop should be
{_HELLO_}
{_TEST_}


HTML HERE
'; // HTML is in here

define('text',$temp,true);

?>

 

Heres how the {_NEWS_} works...

 

<?php

include("template.php");

define('test',true);

$replace = array('{_NEWS_}','{_HELLO_}','{_TEST_}');
$with     = array('NEED TO LOOP HERE','Hello this is a test', 'hello sdasdsd');

echo str_replace($replace,$with,test);

?>

 

 

Now how can i make it so I can put a loop for the {_NEWS_}?

 

edit: Is there anything i can do the TEST constant to go through some script, and come back as a loop?

Link to comment
https://forums.phpfreaks.com/topic/83004-confusing-me/
Share on other sites

This can't simply be done as you wish. Thats half the reason template engines get so bloated, trying to impliment loops.

 

Best you could do (simply) would be something like....

 

<?php

include("template.php");

define('test',true);

# test data and loop.
$arr = array('hello','said','i');
foreach ($arr as $k) {
  $v .= $k;
}

$replace = array('{_NEWS_}','{_HELLO_}','{_TEST_}');
$with     = array($k,'Hello this is a test', 'hello sdasdsd');

echo str_replace($replace,$with,test);

?>

Link to comment
https://forums.phpfreaks.com/topic/83004-confusing-me/#findComment-422174
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.