HowdeeDoodee Posted June 17, 2007 Share Posted June 17, 2007 I need to combine the variable values shown below into a regular expression $composite with a separator of | Any help would be appreciated. Here is an example. $A = "shoe"; $B = "box"; $C = "wrapper"; $termcrm = "crm"; $sep = "|"; $composite = 'shoe|box|wrapper|crm'; Quote Link to comment Share on other sites More sharing options...
chigley Posted June 17, 2007 Share Posted June 17, 2007 <?php $array = array("shoe", "box", "wrapper", "crm"); $sep = "|"; $composite = join($sep, $array); ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 17, 2007 Share Posted June 17, 2007 Well, unless you can put those variables into an array, or unless the variable names follow a pattern, then your only choice is going to be: $composite = $var1.'|'.$var2.'|'.$var3.'|'.$var4;//etc Quote Link to comment Share on other sites More sharing options...
HowdeeDoodee Posted June 17, 2007 Author Share Posted June 17, 2007 OK, gingerrobot thank you for the response. When I tried your suggestion, I got this error message: Parse error: syntax error, unexpected T_VARIABLE The code used was: <?php $A = 'Hello'; $B = 'World'; $C = 'Beautiful'; $D = 'Day!' $composite = $A .'|' . $B . '|' . $C . '|' . $D;// echo $composite; ?> To chigley... Thank you for the suggestion. The values come into a script. I need to convert the values from $variables but not by hand as you show in your example. Thank both of you again. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 17, 2007 Share Posted June 17, 2007 You're missing the semi colon at the end of the line before: <?php $A = 'Hello'; $B = 'World'; $C = 'Beautiful'; $D = 'Day!'; $composite = $A .'|' . $B . '|' . $C . '|' . $D;// echo $composite; ?> Quote Link to comment Share on other sites More sharing options...
HowdeeDoodee Posted June 17, 2007 Author Share Posted June 17, 2007 GingerRobot, I have a red face but am very happy. You are correct both in regard to syntax and my omission. Your solution works. Thank you very much. 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.