replacing variables in output in php

Right now I have this code.

<?php error_reporting(E_ALL); require_once('content_config.php'); function callback($buffer) { // replace all the apples with oranges foreach ($config as $key => $value) { $buffer = str_replace($key, $value, $buffer); } return $buffer; } ob_start("callback"); ?> some content <?php ob_end_flush(); ?>

in the content_config.php file:

$config['SiteName'] = 'MySiteName'; $config['SiteAuthor'] = 'thatGuy';

What I want to do is that I want to replace the placeholders that with the key of the config array with its value.

Right now, it doesn't work :(

-------------Problems Reply------------

your callback function cant see $config. you must either pass it as an argument or declare it global

global $config;

as an aside you can use arrays with str_replace

$buffer = str_replace(array_keys($config), array_values($config), $buffer);

this avoids a loop, which is always good.

Category:php Views:0 Time:2010-05-19
Tags: php

Related post

  • replace variable with its value in a ruby string, string itself is stored in a variable? 2011-07-21

    I have a variable containing a string and in run time i was to replace some variables which are stored in that string. for example.. my_string = "Congrats you have joined groupName." groupName = "*Name of my group*" puts my_string Output:- "Congrats

  • Replace Ajax.ActionLink output to use Jquery 2010-10-13

    Is there an easy way of replacing the generated output of Helper function Ajax.ActionLink to use Jquery instead of MS ? Or must i do all the job in a custom Extension? Someone must have done this EDIT: I think i'm looking at replacing the MicrosoftMV

  • izpack replacing variables in text files 2010-12-27

    I'm trying to figure out how to have izpack replace variables in text files. It seems like it should be a simple thing but I can't find a specific example of doing this with their existing documentation. Any ideas? TIA --------------Solutions--------

  • How replace variable names in an xml-file? 2011-04-26

    The java build tool ant provides filter to replace variables by their values Example: A file with properties: db.driver=com.informix.jdbc.IfxDriver A XML file with generic settings (Note the @[email protected] ) <driver-class>@db.dri

  • Symfony - Why do some variables get output escaped, and others do not? 2011-04-26

    In a Symfony 1.4 view, why do some variables get output escaped, and others do not? I have escaping_strategy = true, and escaping_method = ESC_SPECIALCHARS. If I do $this->form = new SearchForm(); then in my view, $form will be a SearchForm. Or mo

  • Javascript/jQuery library to replace variables in text 2011-09-01

    I have Javascript APIs where users call them with URLs. I may need to replace some parts of the URL, for example they might call my ajax photo upload API with their upload URL:${username};jsessionid=l2k34523 I th

  • replacing/overwriting standard-output in lisp 2011-12-25

    i'm writing a chronometer in common lisp, output is being displayed in standard-output. what i'm trying to do is replace the output without printing a newline and without printing side-by-side but by overwriting the previous output so there is an ill

  • Replace variable value with plain text or ignore it if value is not available 2010-10-29

    I have the following code for javascript: function append_place(street, city, state, country) { var address = street + ', ' + city + ', ' + state + ', ' + country; $(".shop_location").append(address); street, city, state, country are external variabl

  • replace variable value and store it in new variable 2010-12-10

    I have below code to replace the variable value and store it in new variable and leave the original variable intact. #!/usr/bin/perl $hdisk="hdisk361"; ($newdisk) = ($hdisk =~ s/(hdisk\D*)(\d+)/(($1 eq "hdiskpower"?"prw":"dsk").$2)/ei); print "hdisk:

  • Replace variables in all php files 2011-03-11

    I have a tough question about replacing certain variable name across all php files, i.e. to rename _$foo_ to _$bar["foo"]_ in all the php files. I'm planning to read all the php file as text and replace the desired variables, then write back the php

  • Replacing variable text in XSLT file 2011-06-28

    I am using Google Search Application for our website search feature. I am getting the search results in an XML format and i have included the default XSLT file in my application for formatting of the search results. I want to display the XMl results

  • Replace variables values between two files using VBS 2011-08-11

    I'm dealing with a script and I won't be able to create it without your help. This is what I need: I have two .txt files, one contains variables (between two @) like these: @[email protected]=E:/SonicDataFiles/AR_INT/GPP_VE/IN @[email protected]=jdbc:sonic:sqlserv

  • Replacing variable in string possible? 2011-08-28

    If I have a string, and I search in the string for a particular text after a signal, is there any way to output the text string with the particular text after the signal replaced with a variable of the same name? Example I have $strin="This is #fruit

  • replace variables with value in batch file 2012-01-02

    I am having a batch file where it has set variable. I would like replace each variable with value. For ex: My batch file looks like follows Set Sourcefolder=..\..\Release Set Variable2=/y /R Set DestFolder=..\..\Output XCopy %SourceFolder%\Comp1 %Des

  • How to improve Perl regex performance with very large search and replace variables? 2012-01-12

    In Perl search and replace with large variables takes a long time. For example. $original = 'aaaabc'; $replace = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' x 1000 $original =~ s/b/$replace/; Once $replace is of large enough size the regex can t

  • PowerShell: Quoting -replace & variables 2012-02-23

    This is in response to my previous question: PowerShell: -replace, regex and ($) dollar sign woes My question is: why do these 2 lines of code have different output: 'abc' -replace 'a(\w)', '$1' 'abc' -replace 'a(\w)', "$1" AND according to the 2 art

  • Sql - Fetch next value to replace variable value 2013-05-21

    Hi guys my basic sql knowledge needs some help I want to be able to replace a variable value with a value in a table and keep running the query until the end value in the table is reached start query DECLARE @prime_SCHEMA VARCHAR(20) DECLARE @next_SC

  • Add Package-scope Variable to Output (SSIS) 2009-08-07

    I'm trying to create an SSIS package to move data from an Excel spreadsheet into a SQL Server 2005 table. It's mostly going okay, considering that this is the third time I've tried to build a package at all (not what you'd call a flat learning curve)

  • Replacing variable numbers of items- regex? 2009-12-16

    Ok... I have an unsatisfactory solution to a problem. The problem is I have input like so: {sup 19}F({sup 3}He,t){sup 19}Ne(p){sup 18}F and need output like so: ¹⁹F(³He,t)¹⁹Ne(p)¹⁸F I use a series of replacements first to split each of the {sup xx} s

Copyright (C), All Rights Reserved.

processed in 0.156 (s). 11 q(s)