phpSensei Posted December 24, 2007 Share Posted December 24, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83004-confusing-me/ Share on other sites More sharing options...
trq Posted December 24, 2007 Share Posted December 24, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83004-confusing-me/#findComment-422174 Share on other sites More sharing options...
phpSensei Posted December 24, 2007 Author Share Posted December 24, 2007 I simply wish I could be able to create a function for this, but thankyou Thorpe I will try this out.. Quote Link to comment https://forums.phpfreaks.com/topic/83004-confusing-me/#findComment-422179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.