archonik Posted November 11, 2008 Share Posted November 11, 2008 A little backstory: I store my 'items' in an array: $a['ITEMNAME']['ITEMVALUE'] What I'm trying to do is build a piece of BBCode that will allow me to print the value of a provided 'item'... But trying to do so... Fails MISERABLY. My code is (one of the X-ty versions I tried:) $value = preg_replace("/[var](.+?)[/var]/", $a[$1]['itemvalue']', $output); I tried many things... putting the $1 in {} etc. etc. but noting seems to work. Is there any way around that? The replace pattern works ok itself but it's the putting the thing inbetween and using it as a variable... complicates everything... Help, please? Quote Link to comment https://forums.phpfreaks.com/topic/132271-solved-preg_replace-and-vars-problem/ Share on other sites More sharing options...
effigy Posted November 11, 2008 Share Posted November 11, 2008 <pre> <?php $a = array(); $a['test']['itemvalue'] = 123; $output = '0[var]test[/var]456789'; echo preg_replace('%\[var\](.+?)\[/var\]%e', '$a["$1"]["itemvalue"]', $output); ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/132271-solved-preg_replace-and-vars-problem/#findComment-687768 Share on other sites More sharing options...
archonik Posted November 11, 2008 Author Share Posted November 11, 2008 Thank You. That worked great. How do you learn regular expressions without making your brain explode is beyond me... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/132271-solved-preg_replace-and-vars-problem/#findComment-687781 Share on other sites More sharing options...
effigy Posted November 11, 2008 Share Posted November 11, 2008 Carefully Look here. Quote Link to comment https://forums.phpfreaks.com/topic/132271-solved-preg_replace-and-vars-problem/#findComment-687789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.