Jump to content

Recommended Posts

function.php
[code]//Get the HTML_DOCTYPE from gui/html_doctype.txt
   function html_doctype(){
      if(file_exists("gui/html_doctype.txt")){
         $style['html_doctype'] = file_get_contents("gui/html_doctype.txt");
         echo $style['html_doctype'];
      }else{
         echo("Fatal Error: HTML_DOCTYPE not found. Please re-upload html_doctype.txt");
      }
   }

//Change {config|X} to $config['X']
   function parse_config($string){
      $old = array("\{config|url\}", "\{config|mysql_server\}", "\{config|mysql_db\}");
      $new = array($config['url'], $config['sqlserver'], $config['dbname']);
      $new_string = str_replace($old, $new, $string);
      $template_parsed['config'] = $new_string;
   }

//Generate Header
   $template_unparsed['header'] = html_doctype();
   parse_config($template_unparsed['header']);
   echo $template_parsed['config'];[/code]

html_doctype.txt
[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-AU">

<head>
<title>Perth Academy</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="{config|url}/gui/css/style.css" />
</head>[/code]

It doesn't want to replace {config|url} with $config[url]...

Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/11089-str_replace-problems/
Share on other sites

In this piece of code:
[code]<?php
//Change {config|X} to $config['X']
   function parse_config($string){
      $old = array("\{config|url\}", "\{config|mysql_server\}", "\{config|mysql_db\}");
      $new = array($config['url'], $config['sqlserver'], $config['dbname']);
      $new_string = str_replace($old, $new, $string);
      $template_parsed['config'] = $new_string;
   }
?>[/code]
Where is the $config array initialized? I don't see it anywhere, so your $new array doesn't contain what you think it does.

I would pass the $old & $new arrays to your function instead of defining them in the function.

[code]<?php
   $old = array('{config|url}', '{config|mysql_server}', '{config|mysql_db}');
   $new = array($config['url'], $config['sqlserver'], $config['dbname']);
   $template_unparsed['header'] = html_doctype();
   parse_config($template_unparsed['header']);
   echo $template_parsed['config'];

   function parse_config($string,$o, $n){
      $new_string = str_replace($o, $n, $string);
      $template_parsed['config'] = $new_string;
   }
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/11089-str_replace-problems/#findComment-41468
Share on other sites

[!--quoteo(post=379637:date=Jun 3 2006, 10:20 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 3 2006, 10:20 AM) [snapback]379637[/snapback][/div][div class=\'quotemain\'][!--quotec--]
In this piece of code:
[code]<?php
//Change {config|X} to $config['X']
   function parse_config($string){
      $old = array("\{config|url\}", "\{config|mysql_server\}", "\{config|mysql_db\}");
      $new = array($config['url'], $config['sqlserver'], $config['dbname']);
      $new_string = str_replace($old, $new, $string);
      $template_parsed['config'] = $new_string;
   }
?>[/code]
Where is the $config array initialized? I don't see it anywhere, so your $new array doesn't contain what you think it does.

I would pass the $old & $new arrays to your function instead of defining them in the function.

[code]<?php
   $old = array('{config|url}', '{config|mysql_server}', '{config|mysql_db}');
   $new = array($config['url'], $config['sqlserver'], $config['dbname']);
   $template_unparsed['header'] = html_doctype();
   parse_config($template_unparsed['header']);
   echo $template_parsed['config'];

   function parse_config($string,$o, $n){
      $new_string = str_replace($o, $n, $string);
      $template_parsed['config'] = $new_string;
   }
?>[/code]

Ken
[/quote]
Thanks. The $config[x] variables are set in another php file called config.php (don't worry, that is required()).

config.php
[code]//MySQL Details
   //MySQL Database Name
   $config['dbname'] = "";
   //MySQL Server
   $config['sqlserver'] = "localhost";
   //MySQL Username
   $config['sqlusername'] = "";
   //MySQL Password
   $config['sqlpassword'] = "";

//Server Details
   //URL of PASite setup
   $config['url'] = "http://localhost/perthacademy"; //DO NOT END IN TRAILING SLASH.[/code]
Link to comment
https://forums.phpfreaks.com/topic/11089-str_replace-problems/#findComment-41469
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.