Jump to content

[SOLVED] preg_replace/while


Locked

Recommended Posts

Does anyone have any idea why this code is only replacing the last part?

 

url:http://orella.co.uk/index4.php (Check the top left hand corner)

 

<?php
function Template($array,$replace){
$template="template.html";
if(file_exists($template)){
  $template=implode("", file($template));
   $num=0;
  while($array[$num]){
  echo "Replacing: '$array[$num]' with '$replace[$num]'.<br>";
     $page=preg_replace("/{".$array[$num]."}/",$replace[$num],$template);
     $num=$num+1;
     }
   return $page;
}else{
die("Sorry! This theme no longer exists!");
}
}
$array=array("Title","Energy","NAV");
$replace=array("Page Title!","Energy level!","Nav!!");


echo Template($array,$replace);
?>	

 

Link to comment
https://forums.phpfreaks.com/topic/75568-solved-preg_replacewhile/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.