[FX.php List] [OFF] Replace parts of a string w/ non-string elements?

Joel Shapiro jsfmp at earthlink.net
Thu Aug 21 15:20:27 MDT 2008


Hi all

I've got a field in which FileMaker users can enter various field  
names like merge fields, such as:
"Hello <<nameFirst>> ..."

In the PHP, I'd like to be able to automatically replace all  
instances of "<<fieldName>>" from within that field with " $queryData 
['fieldName']  ", such as:
"Hello ' .  $queryData['fieldName'] . ' ..."
(or even "Hello $queryData['fieldName'] ..." with just double-quotes)

Is there any PHP function that can do this?

The problem seems to be stepping out of and back into a string.   
str_replace() just makes the "$queryData" into part of the string,  
when I really want to step *out of* the string.

For the last project there weren't many possible <<mergeFields>>, so  
I worked around this by hard-coding two arrays for use within a  
str_replace() function, as such:

$from = array(
	'&lt;&lt;fieldName1&gt;&gt;',
	'&lt;&lt;fieldName2&gt;&gt;'
	);

$to = array(
	$queryData['fieldName1'],
	$queryData['fieldName2']
	);

But still, I'm curious.  Is there some other way to do this?

TIA,
-Joel


More information about the FX.php_List mailing list