Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.



Add comment:
Name:
Email:
Comment: *
(Use BBcode - No HTML)


You MUST answer this simple math equation - to prevent spammers: 4 + 17 =  


Function to handle string substitution in php

Last updated: 07/03/2009
This php function replaces any occurances of tags in a string with the corresponding hash value in the $_REQUEST hash.

For example, if the string contains , it would be replaced with $_REQUEST["NAME"].  This is good for creating SQL calls, or building output strings.

function substitute ($s) {

    $new_s = preg_replace('/{([a-z_A-Z]+)}/',"".$_REQUEST['$1']."",$s);
    eval('$new_s = "$new_s";');
    return($new_s);
}

}

 


Note - You should change the regular expression to match what you are looking for; you can pass in an arbitrary array with values to substitute.

 

 





Powered by KnowledgebasePublisher 1.1
Superb Internet
Content provided by Roberts WebForge, Inc.