MCrosbie Posted December 19, 2007 Share Posted December 19, 2007 Hi there, I have the following tag, which I want the contents of which to be hidden. This is a email that is being emailed to two people, one who is allowed to view the price, one who isn't. This is what I have at present: <price>$ 10.99</price> (Prices will change) I want this to be replaced with <price>$ --.--</price> Any ideas? Cheers, Michael Quote Link to comment Share on other sites More sharing options...
effigy Posted December 19, 2007 Share Posted December 19, 2007 If this is XML, I recommend building a filter on top of an Indentity Transform with XSLT; although, keeping the specifics (dollar sign, decimal point, number of digits) may be difficult. The regex solution: <pre> <?php $str = '<price>$ 10.99</price>'; echo preg_replace('%((?<=<price>\$\x20)\d+|(?<=\.)\d+(?=</price>))%e', 'str_repeat("-", strlen("$1"))', $str); ?> </pre> Quote Link to comment Share on other sites More sharing options...
dsaba Posted December 20, 2007 Share Posted December 20, 2007 Here's your previous reply effigy: %((?<=<price>\$\x20)\d+|(?<=\.)\d+(?=</price>))%e I changed it to this an noticed the substrings went away. %(?<=<price>\$\x20)\d+|(?<=\.)\d+(?=</price>)%e So am I correct in saying by putting an extra pair of parenthesis around the entire pattern, you can force the full pattern matches into substrings as well? Is there a way to force everything not matched into substrings? Quote Link to comment Share on other sites More sharing options...
effigy Posted December 25, 2007 Share Posted December 25, 2007 So am I correct in saying by putting an extra pair of parenthesis around the entire pattern, you can force the full pattern matches into substrings as well? Right. If you do not capture anything $1 is empty when it is passed to str_repeat. Is there a way to force everything not matched into substrings? Only matches are stored in the array; you can match the undesirables just to get them in the array. Quote Link to comment 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.